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

Header-Endpoint that only matches specific values, akin to path #983

Open
d-s-d opened this issue Sep 16, 2018 · 6 comments
Open

Header-Endpoint that only matches specific values, akin to path #983

d-s-d opened this issue Sep 16, 2018 · 6 comments
Milestone

Comments

@d-s-d
Copy link

d-s-d commented Sep 16, 2018

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
@vkostyukov
Copy link
Collaborator

vkostyukov commented Sep 18, 2018

Perhaps headerExact("foo", "bar") could be a reasonable API to expose (that's what warp uses)?

@vkostyukov
Copy link
Collaborator

@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.

@d-s-d
Copy link
Author

d-s-d commented Oct 3, 2018

@vkostyukov Ok. I'm new to this. Till when would you like to see a PR?

@vkostyukov
Copy link
Collaborator

There is no deadline whatsoever. Whenever you have time.

@sergeykolbasov
Copy link
Collaborator

sergeykolbasov commented Dec 6, 2018

@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

@d-s-d
Copy link
Author

d-s-d commented Dec 8, 2018

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants