How to execute PUT REST client code using playframework in scala

30 Views Asked by At

I am new to Scala and struggling to get a simple PUT REST client working.

I am modifying existing code which is using StandaloneAhcWSClient https://www.playframework.com/documentation/2.6.0-M2/api/java/play/libs/ws/StandaloneWSRequest.html

Version used: play-ws:2.8.0, play-ahc-ws-standalone:2.1.2

  def runUrl(url: String, header: Option[(String, String)] = None, timeOut: Duration = FiniteDuration(1, SECONDS))(implicit executionContext: ExecutionContext): Future[Boolean] = {
    val baseRequest = wsClient.url(url).withRequestTimeout(timeOut)
    val updatedRequest = header.fold(baseRequest){r => baseRequest.withHttpHeaders((r._1, r._2))}
    updatedRequest.put("Dummy String").map{ response =>
      logger.info(s"Why code is not reaching here ???")
      logger.info(s"url: $url got response $response")
    }
  }

While googling out i found POST example which looks similar to my change https://github.com/playframework/play-ws

def postExampleString(ws: play.api.libs.ws.StandaloneWSClient)(
  implicit ec: ExecutionContext) = {
  val stringData = "Hello world"
  ws.url("...").post(stringData).map { response => /* do something */ }
}

Any help would be much appreciated.

0

There are 0 best solutions below