Play Framework Scala Proxy for Http Post

I am using the game! using scala and trying to create proxies for HTTP requests, GET and POST.

The GET actions seem to work, the problem is with the POST action, where I cannot pass the request payload.

I tried several things, for example, the code below, but no one works.

def postAction(query: String) = Action.async { implicit request => val data = if (request.body.asText != None) request.body.asText.get else "" WS.url(DEMO_URL + query).post(data).map(resp => Ok(resp.body).as("application/json")) } 

The last thing to mention is that I'm new to both games! and scala.

+2
source share
1 answer

I had to add parse.json Action.async (parse.json)

Now the code is much simpler and looks like this:

  def postAction(query: String) = Action.async(parse.json) { implicit request => WS.url(DEMO_URL + query).post(request.body).map(resp => Ok(resp.body).as("application/json") ) } 
+4
source

Source: https://habr.com/ru/post/925545/


All Articles