O'Reilly logo

Play Framework Cookbook - Second Edition by Giancarlo Inductivo, Alexander Reelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Consuming external web APIs

In this recipe, we will explore the Play WS API to consume external web services from a Play 2 web application. As web application requirements evolve, we become more dependent on external data services for data such as foreign exchange rates, real-time weather data, and so on. The Play WS library provides us with APIs to be able to interface with external web services.

How to do it…

For Java, we need to perform the following steps:

  1. Run the foo_java application with Hot-Reloading enabled:
        activator "~run"
    
  2. Declare playWs as a project dependency in build.sbt:
        libraryDependencies ++= Seq(
            javaWs
        )
  3. Create a new controller in foo_java/app/controllers/WebClient.java and add the following content:
     package controllers; import ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required