Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an attempt to solve #575 and a last PR in 0.11.
The idea is to use new abstraction
ServiceBuilder
that maps anHList
of endpoints (even coproduct endpoints) to anHList
of content-types. When an actual conversion (toService
) happens we fold un underlying list of endpoints and apply them one-by-one to a given request until it matches. TheHNil
case behaves as 404 (which is very nice).The high-level API is following:
Note that
toService
still works, but marked as deprecated.This is probably not the most efficient and clean solution, but I admire its simplicity and how small the diff itself. None of the
Endpoint
,ToResponse
,Encode
internals/API were touched - everything is done by new code.Please, let me know how do you like the API. The only thing I'm worried about right now is whether or not it's good enough for further steps in this direction (content-type negotiation).