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 - Create endpoint for multiple http verbs #589

Open
jsvilling opened this issue Apr 19, 2024 · 0 comments
Open

EndpointRouting - Create endpoint for multiple http verbs #589

jsvilling opened this issue Apr 19, 2024 · 0 comments

Comments

@jsvilling
Copy link

Issue

With Giraffe default routing it was easy to compose routes to listen to multiple http verbs. One could do someting like:

let private GET_HEAD_OPTIONS: HttpHandler = choose [ GET_HEAD; OPTIONS ]

With endpoint routing this is no longer possible as Endpoints cannot be composed in this way. It is possible to "just" create an endpoint for each needed http verb. However, this can quickly become cumbersome.

Suggestion

It would be very convenient to have a function in the Giraffe Routers module to create an endpoint for multiple http verbs. The Routers module already has a private function to create such endpoints.

To make it easier to create endpoints for multiple verbs one could add a helper function in the style of:

    let forVerbs (verbs: HttpVerb list) =
        verbs
        |> List.distinct
        |> applyHttpVerbsToEndpoints 

This would make it possible to create endpoints for multile http verbs neatly like

    let api = [
        forVerbs [ GET; HEAD; OPTIONS ] [
            route "/api/subpath" handler
        ]
    ]
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

1 participant