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

RequestSyntax.send with generic response type #70

Closed
pinguinson opened this issue Aug 5, 2017 · 1 comment
Closed

RequestSyntax.send with generic response type #70

pinguinson opened this issue Aug 5, 2017 · 1 comment

Comments

@pinguinson
Copy link

I'm trying to get rid of boilerplate methods like this one:

def fetchStuff: Future[List[Stuff]] = {
  val request = someClient.get("stuff").accept("application/json")
  request.send[List[Stuff]]
}

Tried this as well as replacing T in return type with List[T] but to no avail:

def fetch[T](endpoint: String): Future[List[T]] = {
  val request = someClient.get(endpoint).accept("application/json")
  request.send[List[T]]
}

Error:(30, 17) In order to decode a request to T, it must be known that a decoder exists to T from
all the content types that you Accept, which is currently String("application/json") :+: shapeless.CNil.
You may have forgotten to specify Accept types with the `accept(..)` method,
or you may be missing Decoder instances for some content types.
    request.send[T]

Is there any solution or should I just keep my boilerplate code?

@pinguinson
Copy link
Author

Well, turned out I was dumb and forgot to add implicit DecodeAll instance:

def fetch[T](endpoint: String)
            (implicit decodeAll: DecodeAll[List[T], Coproduct.`"application/json"`.T]): Future[List[T]] = {
    val request = api.get(fetcher.endpoint).accept[Coproduct.`"application/json"`.T]
    request.send[List[T]]
}

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

No branches or pull requests

1 participant