Hi Martynas, 

It worked perfectly. Thanks a lot!


On Thursday, April 16, 2015 at 1:42:42 PM UTC+2, Martynas Mickevičius wrote:
>
> Hi Guillaume,
>
> you should use akka-http marshalling/unmarshalling infrastructure to do 
> rendering/parsing. There are predefined unmarshallers available for 
> converting HttpResponses to Strings. You only need to add a mapAsync stage 
> to your flow to make it work:
>
> Source.single(HttpRequest(uri = 
> Uri("/"))).via(httpClient).mapAsync(Unmarshal(_).to[String]).runWith(Sink.head)
>
> For a working example you can clone my sandbox repo where I put this 
> example code 
> <https://github.com/2m/akka-stream-sandbox/blob/d3b39e76e175eb0dfb6cf7046a02d208d6c16103/src/test/scala/ResponseAsString.scala>
> .
>
> On Mon, Apr 13, 2015 at 6:13 PM, Guillaume Breton <[email protected] 
> <javascript:>> wrote:
>
>> Hi all, 
>>
>> I am trying to consume a Json based API using the Http client system.
>>
>> My code is the following :
>>
>> ```scala
>>   implicit val system = ActorSystem("client-system")
>>   implicit val materializer = ActorFlowMaterializer()
>>   val host = "127.0.0.1"
>>   val httpClient = Http(system).outgoingConnection(host, 80)
>>   def get(url: String): Future[HttpResponse] = 
>> Source.single(HttpRequest(uri = Uri("/"))).via(httpClient).
>> runWith(Sink.head)
>> ```
>>
>> The server send a simple valid Json. I try to figure out how to parse the 
>> HttpResponse.entity using a SprayJson protocol. I would like to 
>> get a Future[String].
>>
>> Is there a simple way to map the flow from the httpClient to extract a 
>> String ?
>>
>> Cheers,
>>
>> Guillaume
>>
>> -- 
>> >>>>>>>>>> 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 [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/akka-user.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Martynas Mickevičius
> Typesafe <http://typesafe.com/> – Reactive 
> <http://www.reactivemanifesto.org/> Apps on the JVM
>  

-- 
>>>>>>>>>>      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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to