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

WIP: derive http client from service #368

Conversation

pepegar
Copy link
Member

@pepegar pepegar commented Jul 20, 2018

This is a work in progress to track the status of HTTP client derivation from service protocol (protocol = service annotated trait). The actual implementation:

  • creates a new http object within the generated companion
  • puts a HttpClient[F[_]: Sync] inside the http object
  • creates a new method on HttpClient for each @http annotated method in the protocol, with all the needed.
  • Derive HTTP from [Protobuf|Avro|AvroWithSchema] (like we're doing for RPC).

Some assumptions/questions I've taken while implementing this:

  • all HTTP methods should be unary, meaning that they only take a parameter
  • how do we treat headers? If they're a static value, we can pass them as params to the @http annotation, to try to leave the method as similar to the RPC definition as possible. Otherwise, i haven't found a solution for that, since it'll make method incompatible with RPC...

Test

To see generated code, I've used this file

import freestyle.rpc._
import freestyle.rpc.protocol._
import freestyle.rpc.internal.encoders.pbd._

@service(Avro) trait GithubService[F[_]] {

  @http(POST, "https://github.com/frees-io/freestyle-rpc/issues")
  def postIssue(id: Int): F[String]

  @http(POST, "https://github.com/frees-io/freestyle-rpc/pr")
  def postPullRequest(id: Int): F[String]

}

And loaded directly in the REPL:

$ sbt client/console
scala> :load test.scala

@L-Lavigne
Copy link
Contributor

Closing this PR as resolved in #552. Thanks @pepegar and @rafaparadela !

@L-Lavigne L-Lavigne closed this Mar 18, 2019
@alejandrohdezma alejandrohdezma deleted the feature/derive-http-client-from-service branch April 27, 2021 16:20
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