finch
finch copied to clipboard
Header-Endpoint that only matches specific values, akin to path
It would be convenient to have a header-endpoint that matches iff a header is present with a particular value. This is useful in situations where one wants to provide different business logic depending on that value. An example of this is API-Versioning: Let's assume that such an endpoint-factory would exist and header(x, y)
matched iff header x
was present with value y
. Then one could solve this problem as follows:
val v1Endpoint: Endpoint[ResponseV1] =
get("myEndpoint" :: header("X-API-VERSION", "1")) { /* ... */ }
val v2Endpoint: Endpoint[ResponseV2] =
get("myEndpoint" :: header("X-API-VERSION", "2")) { /* ... */ }
val allVersions = v1Endpoint :+: v2Endpoint
Perhaps headerExact("foo", "bar")
could be a reasonable API to expose (that's what warp uses)?
@d-s-d Let me know if you're willing to contributed this new endpoint instance and I will move the ticket to appropriate milestone.
@vkostyukov Ok. I'm new to this. Till when would you like to see a PR?
There is no deadline whatsoever. Whenever you have time.
@vkostyukov @d-s-d
I just started some work on this one, but it looks like a bit of inconsistency to me. At the moment we always match the header
endpoint. If header(name)
is missing in the headers error is raised.
While headerExact
is supposed to return EndpointResult.NotMatched
instead
@sergeykolbasov That is the point, I think. Similar to the path, this endpoint can be used to dispatch a request. Maybe a different name would do: headerMatch
, or headerDispatch
. Or did I misunderstand your remark?