Route Module
Type-safe routing with discriminated unions.
The Route module provides functions for:
Generating Falco endpoints from route unions Creating type-safe links from route values Hydrating routes with values from HTTP context Validating route structure and preconditions
Example
type PostRoute =
| List
| Show of id: Guid
| Create of PreCondition<UserId>
let config: EndpointConfig<AppError> = {
Preconditions = [ yield! Extractor.precondition<UserId, _> authExtractor ]
Parsers = []
MakeError = fun msg -> BadRequest msg
CombineErrors = List.head
ToErrorResponse = fun e -> Response.ofPlainText (string e)
}
let endpoints = Route.endpoints config handleRoute
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 ...
union case PostRoute.List: PostRoute
--------------------
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
Types
| Type | Description |
|
Full route metadata extracted via reflection. |
Functions and values
| Function or value |
Description
|
Full Usage:
Route.allRoutes ()
Parameters:
unit
Returns: 'TRoute list
A list of all possible route values, with parameterized routes using default values.
|
Enumerates all route cases for a route union type.
Example
val allRoutes: obj seq
val route: obj
val info: obj
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
|
Full Usage:
Route.endpoints config routeHandler
Parameters:
EndpointConfig<'E>
-
Configuration for extraction (preconditions, parsers, error handling).
routeHandler : 'TRoute -> HttpHandler
-
A function that takes a hydrated route value and returns an HTTP handler.
Returns: HttpEndpoint list
A list of Falco HttpEndpoint values ready for use with app.UseFalco.
|
Generates Falco endpoints with automatic route extraction.
This is the main entry point for Falco.UnionRoutes. It:
Example
val config: 'a
Multiple items
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 head: list: 'T list -> 'T
Multiple items
val string: value: 'T -> string -------------------- type string = System.String val handleRoute: route: 'a -> 'b
val route: 'a
val Home: 'a
val p: 'a
val endpoints: obj
val ignore: value: 'T -> unit
|
|
Gets full route metadata for a route value using reflection.
Example
val routeInfo: obj
|
Full Usage:
Route.link route
Parameters:
'T
-
The route value with actual parameter values.
Returns: string
A URL path with parameters substituted.
|
Generates a concrete URL path from a route value by substituting actual field values.
Example
val postId: obj
val url: obj
|
Full Usage:
Route.respond _returns value
Parameters:
Returns<'T>
-
The Returns<'T> phantom value from the route match — binds the response type.
value : 'T
-
The value to serialize as JSON.
Returns: HttpHandler
An HTTP handler that writes the JSON response.
Modifiers: inline Type parameters: 'T |
Sends a JSON response with the type guaranteed by
Example
val handle: route: 'a -> 'b
val route: 'a
Multiple items
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 returns: obj
val id: obj
|
Full Usage:
Route.validate preconditions
Parameters:
PreconditionExtractor<'E> list
-
The list of registered precondition extractors.
Returns: Result<unit, string list>
Ok () if valid, Error with list of all issues if invalid.
|
Full validation: route structure + precondition coverage.
Example
val preconditions: obj list
val result: obj
union case Result.Ok: ResultValue: 'T -> Result<'T,'TError>
|
Full Usage:
Route.validatePreconditions preconditions
Parameters:
PreconditionExtractor<'E> list
-
The list of registered precondition extractors.
Returns: Result<unit, string list>
Ok () if all types are covered, Error with list of missing types if invalid.
|
Validates that all
Example
val preconditions: obj list
union case Result.Ok: ResultValue: 'T -> Result<'T,'TError>
union case Result.Error: ErrorValue: 'TError -> Result<'T,'TError>
val errors: string seq
val failwith: message: string -> 'T
module String
from Microsoft.FSharp.Core
val concat: sep: string -> strings: string seq -> string
|
Full Usage:
Route.validateStructure ()
Parameters:
unit
Returns: Result<unit, string list>
Ok () if valid, Error with list of issues if invalid.
|
Validates route structure including paths and field-to-parameter consistency.
Example
union case Result.Ok: ResultValue: 'T -> Result<'T,'TError>
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
union case Result.Error: ErrorValue: 'TError -> Result<'T,'TError>
val errors: string list
Multiple items
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 iter: action: ('T -> unit) -> list: 'T list -> unit
|
Falco.UnionRoutes