Skip to content

EndpointRouting - Create endpoint for multiple http verbs #589

Open
@jsvilling

Description

@jsvilling

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions