
Learning about REST API and its importance
In the first chapter, we learned about RESTful principles such as client-server, statelessness, cacheable, and layered, and we'll recognize and apply those principles to the low-level yet functional APIs in this chapter. Also, we will learn RESTful API design strategies and best practices that can help us to meet the challenge of any time, anywhere, and any device.
Let's think of an example—assume you're going to an event, where along with other activities there will be a screening of the film Solo (the latest in the Star Wars series), and you know that some of your friends joining the party aren't familiar with Star Wars and the earlier sequels. So being a tech geek, you wanted to help your friends with a simple mobile application that can send search results to your WhatsApp group as messages with details about Star Wars characters, lists of films, starships, and so on; also it sends messages when any of your friends ask for any specific information.
But how can a standalone mobile application get data about Star Wars, how will it use WhatsApp to reply, how can we integrate three different systems (mobile, messaging, and data) and help your friends with their Star Wars queries?
Do we need to create a massive dataset of Star Wars by ourselves? How will the mobile app leverage WhatsApp messaging abilities to send star wars information? How can the message be a search string for our app? And we don't know yet how many more unknowns that we need to solve as part of the development.
And you think it would be great if the Star Wars dataset was readily available and searchable, and there should be an ability within WhatsApp to programmatically send messages to your friends.
After some research say we found the following list of items that gave us the confidence to build a mobile app within a short time:
- A readily available dataset about Star Wars at SWAPI (https://swapi.co/) that the app can leverage, and, not only that, it also exposes a mechanism that we can search and get responses, so we have a solution for the dataset/data store about star wars
- WhatsApp also provides out-of-the-box messaging capabilities that your program can use to send the messages
With the preceding information, let's put the following cues in sequence to visualize the app:
- A friend is asking about Beru on Whatsapp, and so the app picks it up.
- The app uses https://swapi.co/api/people/?search=beru.
- The SWAPI REST API sends a response to the app's request. The app creates a text with details about Beru from the received response.
- The app builds a click chat API request and sends the message to the group.
- https://api.whatsapp.com/send?text=<"Beru Whitesun Lars, born: '47BBY', she belongs to Human Species and from Tatooine Planet">.
- Your friend/groups receive the message—Beru Whitesun Lars, born: "47BBY", she belongs to "Human" Species and from "Tatooine" Planet.
So, by having all necessary details about those REST APIs, you gain confidence to build a mobile app that helps you to send search results as a message to your WhatsApp group, and you are ready to rock the party. Interesting, isn't it?
So, now you know SWAPI and click chat (http://api.whatsapp.com) are REST APIs and can be consumed by any applications as your mobile app consumes those APIs. With our example, can we say that the app is an attempt to address the digitization challenge of any time, anywhere, and any device with RESTful APIs?
Google Maps and Locations, Apple iTunes, Google Books, UK police forces (https://data.police.uk/api/forces), sunrise and sunset timings (https://sunrise-sunset.org/api), and the British National Bibliography (http://bnb.data.bl.uk) are few examples of public APIs.
The REST API examples that we have so far are more reading operations. However, in reality, the APIs can do a lot more, and we will show how well we can design RESTful APIs that can support create, read, update, and delete (CRUD) operations, pagination, filtering, sorting, searching, and much more as you read through this book.
We encourage you to get to know various publicly available APIs, their purpose, response formats, and so on as it will help you to understand and follow the further discussions in this chapter.