When you visit a website, you enter its URL in a browser application. The browser then connects to the server hosting the website and requests the web page. The server processes the request and sends back the requested web page to the browser. The browser then interprets the HTML, CSS, and JavaScript code and displays the web page to you. This process happens over the internet, which is a global network of computers connected to each other.
We can abstract this process by thinking of the browser as the client and the web server hosting the website as the server. The client sends a request to the server, and the server processes the request and sends back a response. This request-response cycle is the foundation of the web.
We will not get into how the the browser figures out where the server is located and how the server knows where to send the response. This is the domain of the Domain Name System (DNS) and the Internet Protocol (IP) suite. For now, we will focus on the request-response cycle between the client and the server.
The browser ans the server both are software applications that communicate with each other over the network. The browser sends a request to the server, and the server sends back a response. The request and response are both messages (text) that follow a specific format. The format must be agreed upon by both the client and the server for them to understand each other. This is the subject of Application Programming Interfaces (APIs).
Application Programming Interface or API is what allows one software application to “talk” to another. For example, imagine connecting your calendar and to-do application and keeping them in sync; you need to work with their APIs. Most modern software applications and almost the entire Web is made up of APIs. In a nutshell, an API is just a set of rules (protocol).
The protocol allows two software systems to be linked regardless of differences in their internal processes, structure, or design. When it comes to the internet and web applications, the most common type of API is the HTTP API. This API uses the Hypertext Transfer Protocol (HTTP) to send and receive messages between the client and the server.
HTTP stands for Hypertext Transfer Protocol. It owes its popularity to the ubiquity of web applications and its simplicity and ease of use. HTTP is the foundation of any data exchange on the Web. At its core, it functions as a request-response protocol in the client-server computing model.
Let’s revisit our example of the browser and the server. When you enter a URL in the browser, the browser sends an HTTP request to the server. The server processes the request and sends back an HTTP response. The request and response are both messages that follow the HTTP protocol.
This simplest thing to do with HTTP is to request a web page. The browser sends an HTTP GET request to the server, and the server sends back the requested web page in the HTTP response. When you enter a URL in the browser, you are making an HTTP GET request to the server hosting the website. The browser takes care of formating and sending the request, and processing the response to display the web page.
This is the most common use of HTTP, but it can do more. For example, you can use HTTP to send data to the server, delete data, or update data.
HTTP is an extensible protocol. However, at its core, it facilitates CRUD operations. CRUD stands for Create, Read, Update and Delete. Almost all internet consumer-related software uses CRUD. You use it every time you ask an application to take your new data or modify the existing one.
The basic HTTP verbs (methods) corresponding to CRUD operations are:
An HTTP request, in addition to an HTTP verb, typically consists of:
An HTTP response typically consists of:
HTTP requests/responses are textual data that must be transferred over the network from one point to another. An API endpoint is the point of entry in a communication channel when client and server interacting. It refers to the URL of a server or service. The endpoint is the URL that the client uses to communicate with the server. For example, when you visit a website, you are using an API endpoint.
The Free Dictionary API provides word definitions, synonyms, antonyms, and translations. It is a free-to-use API that does not require an API key. The API is hosted at https://dictionaryapi.dev/. It has a single endpoint that accepts a word as a query parameter and returns the word’s definition.
The API endpoint is:
We can try this endpoint in the browser by replacing {word}
with a word. For example, to get the definition of the word “hello”, enter the following URL in the browser:
You will notice that the response is in JSON format rather than HTML. This is because the API is designed to be used by software applications rather than humans. The response contains the word’s definition, pronunciation, synonyms, antonyms, and examples of usage. We will use this API to build our dictionary application.
The browser is not the best tool for testing APIs. It is designed to display web pages rather than process API responses. To test APIs, we need a tool that can send HTTP requests and display the responses in a more readable format. Postman is a popular API client that allows you to test APIs by sending requests and viewing responses. You can download Postman from https://www.postman.com/.
Postman was initially a Chrome extension designed to help developers explore APIs. Since then, it has matured into a stand-alone application, an industry standard for designing, documenting, testing, and interacting with APIs.
Open Postman and click on the +
button to create a new API request. Enter the API endpoint in the URL field and click on the Send
button. You will see the API response in the Body
tab. Postman formats the response in a more readable format than the browser.