EffectRunnerExtensions Type
Creates endpoints from effects, with a route format string whose values are parsed and passed to the handler, and
maps them with MapEffectEndpoints.
The methods extend a "runner" of your own: any value whose type has a *>> operator that turns a handler's
effect into a RequestDelegate. The runner decides how the environment is
created for each request, and how the effect's result and errors become a response.
Example
type Runner =
| RunWith of (HttpContext -> AppEnv)
static member ( *>> )(effect: Effect<AppEnv, IResult, AppError>, RunWith createEnv) =
RequestDelegate(fun ctx -> task {
match! Effect.run (createEnv ctx) effect with
| Ok result -> do! result.ExecuteAsync ctx
| Error err -> ctx.Response.StatusCode <- 500
})
let getUser (id: int) = eff {
let! user = Users.load id
return Results.Ok user
}
app.UseRouting().UseEndpoints(fun endpoints ->
let runner = RunWith createEnv
endpoints.MapEffectEndpoints [
runner.RouteGet("/users/%i", getUser)
])
val int: value: 'T -> int (requires member op_Explicit)
--------------------
type int = int32
--------------------
type int<'Measure> = int
Static members
| Static member |
Description
|
Full Usage:
EffectRunnerExtensions.MapEffectEndpoints(builder, endpoints)
Parameters:
IEndpointRouteBuilder
-
The endpoint route builder, e.g. in UseEndpoints
endpoints : Endpoint list
-
The endpoints to map
Modifiers: inline |
Maps the endpoints, with their conventions, and instruments each with
Example
|
Full Usage:
EffectRunnerExtensions.RouteConnect(this, path, routeHandler)
Parameters:
^a
-
The runner, which turns the handler's effect into a request delegate
path : PrintfFormat<'c, unit, unit, ^b, 'd>
-
The route, with format specifiers for the route values
routeHandler : Expr<('d -> ^b)>
-
Creates the effect that handles a request, from the route values
Returns: Endpoint
Modifiers: inline Type parameters: ^a, ^b, 'c, 'd (requires (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate) and (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate) and (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate)) |
Creates a CONNECT endpoint for path, handled by routeHandler. The route
values work as for
|
Full Usage:
EffectRunnerExtensions.RouteDelete(this, path, routeHandler)
Parameters:
^a
-
The runner, which turns the handler's effect into a request delegate
path : PrintfFormat<'c, unit, unit, ^b, 'd>
-
The route, with format specifiers for the route values
routeHandler : Expr<('d -> ^b)>
-
Creates the effect that handles a request, from the route values
Returns: Endpoint
Modifiers: inline Type parameters: ^a, ^b, 'c, 'd (requires (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate) and (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate) and (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate)) |
Creates a DELETE endpoint for path, handled by routeHandler. The route
values work as for
|
Full Usage:
EffectRunnerExtensions.RouteGet(this, path, routeHandler)
Parameters:
^H
-
The runner, which turns the handler's effect into a request delegate
path : PrintfFormat<'Printer, unit, unit, ^Eff, 'T>
-
The route, with format specifiers for the route values
routeHandler : Expr<('T -> ^Eff)>
-
Creates the effect that handles a request, from the route values
Returns: Endpoint
Modifiers: inline Type parameters: ^H, ^Eff, 'Printer, 'T (requires (static member op_MultiplyGreaterGreater : ^Eff * ^H -> Microsoft.AspNetCore.Http.RequestDelegate) and (static member op_MultiplyGreaterGreater : ^Eff * ^H -> Microsoft.AspNetCore.Http.RequestDelegate) and (static member op_MultiplyGreaterGreater : ^Eff * ^H -> Microsoft.AspNetCore.Http.RequestDelegate)) |
Creates a GET endpoint for path, handled by routeHandler.
The route values are written as format specifiers, which also constrain the route:
Example
val getOrderLine: orderId: int * line: int -> 'a
val orderId: int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val line: int
|
Full Usage:
EffectRunnerExtensions.RouteHead(this, path, routeHandler)
Parameters:
^a
-
The runner, which turns the handler's effect into a request delegate
path : PrintfFormat<'c, unit, unit, ^b, 'd>
-
The route, with format specifiers for the route values
routeHandler : Expr<('d -> ^b)>
-
Creates the effect that handles a request, from the route values
Returns: Endpoint
Modifiers: inline Type parameters: ^a, ^b, 'c, 'd (requires (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate) and (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate) and (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate)) |
Creates a HEAD endpoint for path, handled by routeHandler. The route
values work as for
|
Full Usage:
EffectRunnerExtensions.RouteOptions(this, path, routeHandler)
Parameters:
^a
-
The runner, which turns the handler's effect into a request delegate
path : PrintfFormat<'c, unit, unit, ^b, 'd>
-
The route, with format specifiers for the route values
routeHandler : Expr<('d -> ^b)>
-
Creates the effect that handles a request, from the route values
Returns: Endpoint
Modifiers: inline Type parameters: ^a, ^b, 'c, 'd (requires (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate) and (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate) and (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate)) |
Creates a OPTIONS endpoint for path, handled by routeHandler. The route
values work as for
|
Full Usage:
EffectRunnerExtensions.RoutePatch(this, path, routeHandler)
Parameters:
^a
-
The runner, which turns the handler's effect into a request delegate
path : PrintfFormat<'c, unit, unit, ^b, 'd>
-
The route, with format specifiers for the route values
routeHandler : Expr<('d -> ^b)>
-
Creates the effect that handles a request, from the route values
Returns: Endpoint
Modifiers: inline Type parameters: ^a, ^b, 'c, 'd (requires (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate) and (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate) and (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate)) |
Creates a PATCH endpoint for path, handled by routeHandler. The route
values work as for
|
Full Usage:
EffectRunnerExtensions.RoutePost(this, path, routeHandler)
Parameters:
^a
-
The runner, which turns the handler's effect into a request delegate
path : PrintfFormat<'c, unit, unit, ^b, 'd>
-
The route, with format specifiers for the route values
routeHandler : Expr<('d -> ^b)>
-
Creates the effect that handles a request, from the route values
Returns: Endpoint
Modifiers: inline Type parameters: ^a, ^b, 'c, 'd (requires (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate) and (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate) and (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate)) |
Creates a POST endpoint for path, handled by routeHandler. The route
values work as for
|
Full Usage:
EffectRunnerExtensions.RoutePut(this, path, routeHandler)
Parameters:
^a
-
The runner, which turns the handler's effect into a request delegate
path : PrintfFormat<'c, unit, unit, ^b, 'd>
-
The route, with format specifiers for the route values
routeHandler : Expr<('d -> ^b)>
-
Creates the effect that handles a request, from the route values
Returns: Endpoint
Modifiers: inline Type parameters: ^a, ^b, 'c, 'd (requires (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate) and (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate) and (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate)) |
Creates a PUT endpoint for path, handled by routeHandler. The route
values work as for
|
Full Usage:
EffectRunnerExtensions.RouteTrace(this, path, routeHandler)
Parameters:
^a
-
The runner, which turns the handler's effect into a request delegate
path : PrintfFormat<'c, unit, unit, ^b, 'd>
-
The route, with format specifiers for the route values
routeHandler : Expr<('d -> ^b)>
-
Creates the effect that handles a request, from the route values
Returns: Endpoint
Modifiers: inline Type parameters: ^a, ^b, 'c, 'd (requires (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate) and (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate) and (static member op_MultiplyGreaterGreater : ^b * ^a -> Microsoft.AspNetCore.Http.RequestDelegate)) |
Creates a TRACE endpoint for path, handled by routeHandler. The route
values work as for
|
Orsak