Having some success with Either unmarshaller. I don't think it's
documented, but here's a test:

https://github.com/akka/akka-http/blob/master/akka-http-tests/src/test/scala/akka/http/scaladsl/unmarshalling/UnmarshallingSpec.scala

On Tue, Aug 22, 2017 at 11:16 AM, Richard Rodseth <rrods...@gmail.com>
wrote:

> I'm trying to use Akka HTTP client (singleRequest) with an API that
> returns different JSON for the success and error cases. How is that best
> handled? Also, I'm not sure if the explicit marshalling and unmarshalling
> below is the right way to do things.
>
> Any help much appreciated.
>
> def addUser(baseURL: String, userAttributes: AddUserRequestDTO,
> cookieHeader: Cookie)(implicit http: HttpExt, materializer: Materializer,
> ec: ExecutionContext) = {
>     val headers = List(cookieHeader)
>     val addUserURL = ...
>
>     val responseFuture = for {
>       requestEntity <- Marshal(userAttributes).to
>     val request = HttpRequest(method = HttpMethods.POST, uri = addUserURL,
> headers = headers, entity = requestEntity)
>       response <- http.singleRequest(request)
>       x <- Unmarshal(response.entity).to[AddUserResponseDTO]
>       //body <- response.entity.dataBytes.runFold(ByteString(""))(_ ++ _)
>       //val x = body.utf8String
>     } yield (response, x)
>     responseFuture
>
>   }
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to