Extractor Module
Factory functions for creating extractors to use with EndpointConfig.
Route.endpoints needs to know how to populate each field in your route types:
Built-in types (Guid, string, int, bool) - automatic Single-case DU wrappers (e.g., PostId of Guid) - automatic Custom types - use Extractor.parser PreCondition/OverridablePreCondition fields - use Extractor.precondition (covers both)
Example
let config: EndpointConfig<AppError> = {
Preconditions = [ yield! Extractor.precondition<UserId, _> requireAuth ]
Parsers = [
Extractor.parser<Slug> (fun s -> Ok (Slug s)) // no constraint
Extractor.constrainedParser<Slug> [| RouteConstraint.Alpha |] (fun s -> Ok (Slug s)) // adds :alpha
Extractor.typedParser<bool, Toggle> (fun b -> Ok (if b then On else Off)) // adds :bool
]
MakeError = fun msg -> BadRequest msg
CombineErrors = fun errors -> errors |> List.head
ToErrorResponse = fun e -> Response.ofPlainText (string e)
}
module List from Microsoft.FSharp.Collections
--------------------
type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T with get member IsEmpty: bool with get member Item: index: int -> 'T with get ...
val string: value: 'T -> string
--------------------
type string = System.String
Functions and values
| Function or value |
Description
|
Full Usage:
Extractor.constrainedParser constraints parser
Parameters:
RouteConstraint[]
-
ASP.NET Core route constraints to apply (e.g., Alpha).
parser : Parser<'T>
-
Function that parses a string into the target type.
Returns: FieldParser
A FieldParser for EndpointConfig.
|
Registers a string parser with explicit route constraints.
Use this when you want ASP.NET Core to validate the route parameter before your parser runs.
For example,
|
Full Usage:
Extractor.parser parser
Parameters:
Parser<'T>
-
Function that parses a string into the type.
Returns: FieldParser
A FieldParser for EndpointConfig.
|
Registers a parser for a custom type used in route or query parameters.
Only needed for custom types. Built-in types and single-case DU wrappers around built-in types are handled automatically. This parser adds no route constraints. Use Extractor.constrainedParser
to add constraints (e.g.,
|
Full Usage:
Extractor.precondition extractor
Parameters:
Extractor<'T, 'E>
-
Async function that extracts the value from HTTP context.
Returns: PreconditionExtractor<'E> list
A list of PreconditionExtractors covering both PreCondition and OverridablePreCondition.
|
Registers an async extractor for both
|
Full Usage:
Extractor.preconditionSync extractor
Parameters:
SyncExtractor<'T, 'E>
-
Synchronous function that extracts the value from HTTP context.
Returns: PreconditionExtractor<'E> list
A list of PreconditionExtractors covering both PreCondition and OverridablePreCondition.
|
Registers a sync extractor for both
|
Full Usage:
Extractor.typedParser parser
Parameters:
'TInput -> Result<'TOutput, string>
-
Function that converts the pre-parsed typed value into the target type.
Returns: FieldParser
A FieldParser for EndpointConfig.
|
Registers a typed parser where the input type determines the implicit route constraint.
The parser receives a pre-parsed typed value (not a raw string) because the ASP.NET Core
route constraint guarantees the format. For example, a
|
Falco.UnionRoutes