EndpointRouting - Create endpoint for multiple http verbs
jsvilling opened this issue · comments
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
]
]