Open shaif-dorIT opened 1 year ago
Why don't you use the routex
?
Why don't you use the
routex
?
It looks like routex
isn't supported for the endpoint router.
The documentation does state the default and endpoint router can be used side by side, but I think it would be more elegant to add support for routex
and/or adding a simple wildcard router function to the endpoint router.
After some searching I saw Giraffe maps route
directly to IEndpointRouteBuilder.Map[Methods]
so we can just use a catch-all route template.
let health: HttpHandler = setStatusCode StatusCodes.Status200OK >=> json {| Message = "OK" |}
let notFound: HttpHandler = setStatusCode StatusCodes.Status404NotFound >=> json {| Message = "Not found" |}
let endpoints =
[
GET [
route "/health" health
]
route "{*url}" notFound
]
Hi,
I started using F# and giraffe in order to learn Functional Programming.
I think that the title says it all, but I elaborate:
In regular route with the
routex
you can use regex route with "/*" to get catchall route.How can I mimic that behavior in endpoint routing so I can get a custom handler for dealing with 404 in the endpoint list that is needed in
.UseEndpoints(fun e -> e.MapGiraffeEndpoints(endpoints))