title: how to mock external WS API calls in Scala Play framework
body: <p>I have an existing Scala play application which has a REST API that calls another external REST API. I want to mock the external Web service returning fake JSON data for internal tests. Based on example from: <a href="https://www.playframework.com/documentation/2.6.x/ScalaTestingWebServiceClients" rel="nofollow noreferrer">https://www.playframework.com/documentation/2.6.x/ScalaTestingWebServiceClients</a></p>
  
  <p>I followed example exactly as in Documentation and I'm getting compiler errors due to deprecated class Action.</p>
  
  <pre><code>import play.core.server.Server
  import play.api.routing.sird._
  import play.api.mvc._
  import play.api.libs.json._
  import play.api.test._
  
  import scala.concurrent.Await
  import scala.concurrent.duration._
  
  import org.specs2.mutable.Specification
  import product.services.market.common.GitHubClient
  
  class GitHubClientSpec extends Specification {
    import scala.concurrent.ExecutionContext.Implicits.global
  
    "GitHubClient" should {
      "get all repositories" in {
  
        Server.withRouter() {
          case GET(p"/repositories") =&gt; Action {
            Results.Ok(Json.arr(Json.obj("full_name" -&gt; "octocat/Hello-World")))
          }
        } { implicit port =&gt;
          WsTestClient.withClient { client =&gt;
            val result = Await.result(
              new GitHubClient(client, "").repositories(), 10.seconds)
            result must_== Seq("octocat/Hello-World")
          }
        }
      }
    }
  }
  </code></pre>
  
  <blockquote>
    <p>object Action in package mvc is deprecated: Inject an ActionBuilder
    (e.g. DefaultActionBuilder) or extend
    BaseController/AbstractController/InjectedController</p>
  </blockquote>
  
  <p>And this is the primary example from latest official docs which in fact contains a compile time error, given this example doesn't work how should be the proper way to easily mock an external API using Scala Play?</p>