Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EndpointRouting - Catch All Endpoint for Custom 404 error messages #537

Open
shaif-dorIT opened this issue Jan 30, 2023 · 3 comments
Open

Comments

@shaif-dorIT
Copy link

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))

@64J0
Copy link
Member

64J0 commented Aug 3, 2023

Why don't you use the routex?

@esbenbjerre
Copy link
Contributor

esbenbjerre commented Oct 12, 2023

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.

@esbenbjerre
Copy link
Contributor

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
  ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants