Skip to content

Support composable Methods #3842

@paulpdaniels

Description

@paulpdaniels

Is your feature request related to a problem? Please describe.

It's is clumsy it zio-http 3.x to encode a route that can match multiple methods. There are effectively only two options:

  1. Create multiple routes for each method:
Routes(
  Method.GET / "foo" -> handler,
  Method.PUT / "foo" -> handler
)
  1. Use the ANY method to capture all methods.

1 makes the declaration overly verbose especially if you have to enumerate many of the methods. While 2 is subject to confusing precedence rules.

Describe the solution you'd like

I would like the ability to define multiple methods for a single handler, this is useful in protocols like GraphQL where users may submit via either GET or POST. The easiest way I can think of doing this is to provide a | method that declares that a route will match either of the methods. The internals of this could probably be achieved with a bit mask, but it would be a breaking change to the current implementation, which doesn't have a "composite" concept.

Then the above could be written:

Routes(
  Method.GET | Method.PUT / "foo" -> handler
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions