Advanced Lesson 2
HTTP Requests
Chapter 3: REST API
Web APIs
Great! You have managed to retrieve a webpage with HTTP requests.
These days, you (a client) will mostly communicate with servers via a Web API.
A Web API (Application Programming Interface) lets servers define how clients should communicate with them programmatically. You can also think of APIs being a collection of functions that the server has provided for you to call. Sort of like the public ‘gateway’ to access a service the server provides.
For example, randomuser.me provides a public API to generate a random user.
You can access the API via their provided endpoint https://randomuser.me/api. If you try out the link, you will get a JSON
object as a response. You can also ask the endpoint to generate a random female user by providing some parameters, i.e. https://randomuser.me/api/?gender=female.
The main use of Web API is to provide web services for applications to use. For example, you can add use the YouTube Data API to add a search function to your app to search YouTube videos. Or you can use the Unified API from Transport for London to build an app with live London Tube and bus updates.
Note the subtle difference that unlike a web server that simply serves an HTML file (e.g. http://www.josiahwang.com/index.htm), these endpoints might actually not be folders or files at all. For example, api
above is most likely not a directory on the server. They might just be labels that point to a function to be executed on the server side.