'Return original response from webservice call on scala with play
I have have a scala project (V. 2.12.12) witch use play framework and i try to call webservice and return response.
To do that, i create a client :
override def postStatus(body: JsValue): Future[WSResponse] = {
wsClientHelper.callWS(updateStatusUrl, POST, callerBody = body)
}
My method return Future[WSResponse]. So i call them in a controller :
def postKycStatus: Action[AnyContent] = action.async { implicit request =>
kycRepository
.postStatus(request.body.asJson.getOrElse(JsObject.empty))
}
But when i do that, i can call the updateStatus api sucessfully with postStatus but i got an compilation error :
play.sbt.PlayExceptions$CompilationException: Compilation error[type mismatch; found : scala.concurrent.Future[play.api.libs.ws.WSResponse] required: scala.concurrent.Future[play.api.mvc.Result]]
How can i return my original webservice response with original status code ?
Thanks to your help !
Solution 1:[1]
I found the response. You can do it with:
def postKycStatus: Action[AnyContent] = action.async { implicit request =>
kycRepository
.postStatus(request.body.asJson.getOrElse(JsObject.empty))
.map(response => Status(response.status)(response.body).as(JSON))
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jérémy |
