Hi,

I'm using Akka Http and got working an example project. I added a handler 
for a JSON POST. I can parse the payload to JSON but the print statement 
after that doesn't show in the console and I don't understand why. This is 
my (experimental) code:

  def asyncHandler(request: HttpRequest): Future[HttpResponse] = {

 

    request match {

 

      case HttpRequest(POST, Uri.Path("/listItem"), _, _, _) => {


        val entity = request.entity

        

        val foo: Future[String] = Unmarshal(request.entity).to[String]

        

        println("received POST, foo: " + foo)


        

        foo.map { str =>  


          println("in map...")  // this shows in the console        


          val json = str.parseJson

          

          println("json: " + json) // this doesn't show

        }

        

        Thread.sleep(1000)

        

        Future(HttpResponse(entity = "")

      }

      ...

}


Why is the second print statement in map never shown? I thought maybe it 
could be a timing issue as this is is future closure so I added the 
Thread.sleep but this doesn't make sense. My Json payload is also very 
small.


Additionally, is this the correct way to parse JSON? I found there are 
several ways, here I'm using the spray library, but there's also play 
framework Json parser... Is there a way to get directly a json object from 
the entity instead of parsing first to a string?


Thanks in advance, I'm new to Akka and Spray and also don't have a lot of 
experience with Scala so I apologise for my ignorance.

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