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

Introduce ServiceBuilder #583

Closed
wants to merge 1 commit into from
Closed

Conversation

vkostyukov
Copy link
Collaborator

This is an attempt to solve #575 and a last PR in 0.11.

The idea is to use new abstraction ServiceBuilder that maps an HList of endpoints (even coproduct endpoints) to an HList 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. The HNil case behaves as 404 (which is very nice).

The high-level API is following:

val service = ServiceBuilder()
  .respond[Application.Json](getUsers :+: postUsers :+: deleteUser)
  .respond[Text.Plain](healthcheck)
  .toService

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

@vkostyukov vkostyukov force-pushed the vk/content-type-wrapper branch 3 times, most recently from 5fcf323 to 9f7d9bc Compare April 5, 2016 03:46
@codecov-io
Copy link

Current coverage is 74.10%

Merging #583 into master will increase coverage by +0.02% as of 9d92cd2

Powered by Codecov. Updated on successful CI builds.

@vkostyukov vkostyukov force-pushed the vk/content-type-wrapper branch from 9f7d9bc to 13e31c8 Compare April 5, 2016 22:10
@vkostyukov vkostyukov force-pushed the vk/content-type-wrapper branch from 13e31c8 to 740f0e0 Compare April 5, 2016 22:47
}

object ServiceBuilder {
def apply(): ServiceBuilder[HNil, HNil] = ServiceBuilder(HNil)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nitpicky, but I think I'd prefer either empty or just a respond[CT <: String] method here that would give you a ServiceBuilder(HNil).respond[CT] (just because Foo() screams "side effects" to me and is kind of a workaround for syntactic limitations in Scala anyway). I'd also be happy to keep it as is, though.

@vkostyukov
Copy link
Collaborator Author

See #794 instead.

@vkostyukov vkostyukov closed this Jun 12, 2017
@sergeykolbasov sergeykolbasov mentioned this pull request Oct 8, 2017
9 tasks
@vkostyukov vkostyukov deleted the vk/content-type-wrapper branch October 10, 2018 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants