Logo Orsak

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 effect: 'a
union case Runner.RunWith: (obj -> obj) -> Runner
val createEnv: (obj -> obj)
val task: TaskBuilder
union case Result.Ok: ResultValue: 'T -> Result<'T,'TError>
union case Result.Error: ErrorValue: 'TError -> Result<'T,'TError>
val getUser: id: int -> 'a
val id: int
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int

Static members

Static member Description

EffectRunnerExtensions.MapEffectEndpoints(builder, endpoints)

Full Usage: EffectRunnerExtensions.MapEffectEndpoints(builder, endpoints)

Parameters:
Modifiers: inline

Maps the endpoints, with their conventions, and instruments each with EffectDiagnostics.

builder : IEndpointRouteBuilder

The endpoint route builder, e.g. in UseEndpoints

endpoints : Endpoint list

The endpoints to map

Example

 app.UseRouting().UseEndpoints(fun endpoints ->
     endpoints.MapEffectEndpoints [
         runner.RouteGet("/users/%i", getUser)
         runner.RoutePost("/users", createUser)
     ])

EffectRunnerExtensions.RouteConnect(this, path, routeHandler)

Full Usage: EffectRunnerExtensions.RouteConnect(this, path, routeHandler)

Parameters:
    this : ^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 RouteGet.

this : ^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

EffectRunnerExtensions.RouteDelete(this, path, routeHandler)

Full Usage: EffectRunnerExtensions.RouteDelete(this, path, routeHandler)

Parameters:
    this : ^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 RouteGet.

this : ^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

EffectRunnerExtensions.RouteGet(this, path, routeHandler)

Full Usage: EffectRunnerExtensions.RouteGet(this, path, routeHandler)

Parameters:
    this : ^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: %s for a string, %i for an int, %d for an int64, %b for a bool, %c for a char, %f for a float and %O for a Guid; %% is a literal %. The handler takes the values as a tuple, or a single value, or unit for a route without values, and the names of its parameters name the route values, so pass a function or a lambda directly.

this : ^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
Example

 let getOrderLine (orderId: int, line: int) = eff { ... }

 // maps GET /orders/{orderId:int}/lines/{line:int}
 runner.RouteGet("/orders/%i/lines/%i", getOrderLine)
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

EffectRunnerExtensions.RouteHead(this, path, routeHandler)

Full Usage: EffectRunnerExtensions.RouteHead(this, path, routeHandler)

Parameters:
    this : ^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 RouteGet.

this : ^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

EffectRunnerExtensions.RouteOptions(this, path, routeHandler)

Full Usage: EffectRunnerExtensions.RouteOptions(this, path, routeHandler)

Parameters:
    this : ^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 RouteGet.

this : ^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

EffectRunnerExtensions.RoutePatch(this, path, routeHandler)

Full Usage: EffectRunnerExtensions.RoutePatch(this, path, routeHandler)

Parameters:
    this : ^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 RouteGet.

this : ^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

EffectRunnerExtensions.RoutePost(this, path, routeHandler)

Full Usage: EffectRunnerExtensions.RoutePost(this, path, routeHandler)

Parameters:
    this : ^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 RouteGet.

this : ^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

EffectRunnerExtensions.RoutePut(this, path, routeHandler)

Full Usage: EffectRunnerExtensions.RoutePut(this, path, routeHandler)

Parameters:
    this : ^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 RouteGet.

this : ^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

EffectRunnerExtensions.RouteTrace(this, path, routeHandler)

Full Usage: EffectRunnerExtensions.RouteTrace(this, path, routeHandler)

Parameters:
    this : ^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 RouteGet.

this : ^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

Type something to start searching.