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, ...

Get Play Framework Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.