This article shows how to make remote requests to services using Scala and the Play-Framework. It documents some recommended features that can improve the reliability of the request.
Setup Make sure you add the following dependency to build.sbt
libraryDependencies += ws GET request GET request to a remote service
1import scala.concurrent.Future 2import play.api.http.Status._ 3import play.api.libs.ws.WSClient 4import play.api.libs.json.{JsSuccess, Json} 5 6case class UnexpectedResponseStatus(message: String) extends Exception(message) 7case class InvalidServiceResponse(message: String) extends Exception(message) 8 9class SomeClass @Inject()( 10 ws: WSClient 11) { 12 def getFromRemoteService(url: String): Future[Option[MyClass]] = { 13 ws.