Chapter 2. Working with web APIs
This chapter covers
- Structure of a simple API
- Ways to inspect calls to an API
- Interaction between an API and a client application
- Deployment of the sample API and application on your system
The next few chapters cover the server-client interaction in detail, but this chapter helps you understand the concepts with a simple example of an API and sample application. Most basic API examples use a to-do list, but that’s kind of overused. I decided to go a different way: I’ve selected a list application with pizza toppings. Note that this particular application is simple by design; the goal is to show you how to interact with the API, and how an application interacts with an API. If this were a production application it would have a full pizza, or pizzas, and the database wouldn’t be shared, but for the goals here I’ve taken out as much complexity as possible to make the basic principles clear.
Looking at an API is interesting, but it doesn’t necessarily help you to understand how it can drive an application. Additionally, performing actions such as create and delete in a browser is challenging, so in addition to the API I’ve included a simple application using this API with JavaScript. This application exercises all the functionality in the API so you can see how an application interacts with a web API.