I am trying to take an http request and send it to another service. I want to use the json sent from the first POST and send it on to the next service. The problem I am having is turning the POST data as json and put it into a new POST but it is not Play's type Writeable.
Here is the code:
def postProxyParse(proxyUrl: String) = Action.async { request =>
var url = buildUrl(request.uri)
val data = request.body.asJson
if(url ==""){
badRequest(null, "Url Not matching proxy possibilities")
}
WS.url(url).post(data).map { response =>
Ok(response.body)
}
}
The Error I am getting is Cannot write an instance of Option[play.api.libs.json.JsValue] to HTTP response. Try to define a Writeable[Option[play.api.libs.json.JsValue]]
Ok(data)orOk(response.body.asJson)?val data = request.body.asJson.getOrElse(badRequest(null, "Bad JSON")).