Open
Description
Hi there,
I tried different ways but I just can't get the LinkGenerator to work with routef.
Let's say I have this endpoints:
let endpoints =
[
GET [
route "/houses" readHauses |> addMetadata(EndpointNameMetadata "get_houses")
routef "/houses/%s" readHauseBy |> addMetadata(EndpointNameMetadata "get_house")
]
]
and this 2 handlers:
let readHauses: HttpHandler =
fun (next : HttpFunc) (ctx : HttpContext) ->
let linkGenerator = ctx.GetService<LinkGenerator>()
let data = houses |> List.map(fun house ->
{ Name = house
Links = [{ Rel = "self"
Href = linkGenerator.GetUriByName(ctx, "get_houses")
Method = "GET" }]
})
json data next ctx
let readHauseBy (name: string): HttpHandler =
fun (next : HttpFunc) (ctx : HttpContext) ->
let arr = new ResizeArray<string>()
arr.Add("Gryffindor")
let linkGenerator = ctx.GetService<LinkGenerator>()
let link2 = linkGenerator.GetUriByName(ctx, "get_house", "name", "teest")
let link1 = linkGenerator.GetUriByName(ctx, "get_house", arr)
let link3 = linkGenerator.GetUriByName(ctx, "get_house")
let link3 = linkGenerator.GetUriByName(ctx, "get_house")
json {| Name = name; Capacity = 200 |} next ctx
In the first handler I am able to get the Uri by name. In the second... well.. no way. Ideas? In C# we can use it like this:
app.MapGet("/houses/{id}", (int id) =>
{
return Results.Ok();
})
.WithMetadata(new EndpointNameMetadata("get_product"));
but here I have "{id} in the string, not "%s" I guess this might cause some issues. Any hints?
Metadata
Metadata
Assignees
Labels
No labels