I am calling a webservice like this:
WS
.url(url)
.get
.map { response => // error occurs on this line
response.status match {
case 200 => Right(response.json)
case status => Left(s"Problem accessing api, status '$status'")
}
}
The complete error: Error: Cannot find an implicit ExecutionContext, either require one yourself or import ExecutionContext.Implicits.global
According to this issue, it is fixed in the documentation. I needed to add the following import:
import play.api.libs.concurrent.Execution.Implicits._
Since Play 2.4 you can inject default execution context
via Guice dependency: injection.
class Foo @Inject()()(implicit ec:ExecutionContext) {
def bar() = {
WS.url(url)
.get
.map { response => // error occurs on this line
response.status match {
case 200 => Right(response.json)
case status => Left(s"Problem accessing api, status '$status'")
}
}
}
An alternative option:
import scala.concurrent.ExecutionContext.Implicits.global