Calling remote web services
Web applications sometimes make use of an external web service. For this purpose, Play provides an HTTP client. To use it, add the following dependency to your build:
libraryDependencies += ws
In Java, the library is named javaWS
:
libraryDependencies += javaWs
Background – the OAuth 2.0 protocol
Though some web services can be freely used, most of them provide only authenticated APIs. The OAuth 2.0 protocol is often used as an authentication system. You can find more about OAuth at http://oauth.net/2/. Incidentally, authenticating using OAuth requires calling a web service (the authorization server as depicted in the following figure), so we will implement an OAuth client to illustrate how to call web services:
As a reminder, the preceding figure shows a typical workflow using OAuth. In this scenario, the user performs some action that requires the application to get a resource held by an external resource server, on behalf of the user. The application starts by redirecting...