API integration
When we build Java web applications, we can integrate with external APIs to extend the functionality of our applications. An example would be a weather service API that can be used to display the local temperature on a site. For this section, we will focus on the Representational State Transfer (RESTful) services because those are the most common type of web API.
The RESTful APIs use standard HTTP methods, such as the GET
and POST
examples from the previous section. As you would expect, RESTful APIs communicate primarily through HTTP data exchanges using JSON and XML formats.
When we implement an API, we first learn what its required request methods are, as well as the prescribed format for requests and responses. It is increasingly common for APIs to require authentication, so that might be something you will need to contend with using API keys or other authorization techniques.
The example that follows demonstrates a simple application that implements a weather...