Have you guys ever wondered how your browser talks with google.com or how just with a couple of clicks your reel gets live in front of millions of users?
You will get answers to these questions here in this article, and I can assure you that all these complex concepts will be a piece of cake for you after reading this article.
Key takeaways from this article
What is an API
Client and server
All about request and response
What are APIs and why should we use it
Application Programming Interface (API) is the way for communication between two computers over a network. In simple words, API is just like a telephone call between the client app and the server. Let's imagine a real-world scenario to understand this, so If you want to search for something on Google, the first step is you will open a browser(this is the client), then you will search for something on Google (google is the server) all you will get your desired results. Here internet connection is the network and all this passing of information is done by an API.
let's imagine another real-world scenario to understand API more clearly. Suppose you went to a restaurant, then you asked the water for your order, then he forwards your order to the kitchen, again the kitchen forwards your order to the waiter and at last the waiter serves your order on the table. Now here you are the client the waiter is the API i.e. mode of communication and passing of orders between you and kitchen and the kitchen is playing the role of server.
Now you must have got a clear idea of what is an API so now let's know about the uses of API. In the last example we saw that you went to a restaurant and ordered some food(say pizza), Now if you cloud have made the pizza at home from scratch, It would take more time to prepare, most of making a single pizza at home is more than that ordering it, and also you will take more time to prepare a single pizza than the restaurant. But in for the restaurant they are thousands of orders in a single day resulting in lowering the pice of making a single pizza, they have experienced cooks so you will get your pizza in less than 15 minutes and the most important you don't need to worry about how its made. Similarly, API allows us to add and integrate programming features and functions easily in a few steps with a cheaper cost than building and maintaining that feature. Like if you want authentication in your app you don't need to build it from scratch you can use Auth0 API, or if you want to implement a maps feature you don't need to build it from scratch you can simply use google maps or Mapbox API. One more thing API also allows enterprises to build and integrate products and features faster.
The client and Server
In the earlier paragraphs, I have mentioned the terms client and server so let's understand these two things. The client here can be a browser, mobile app, desktop app, etc with which the user interacts, it has a wonderful UI and is easy to understand and no programming experience is needed to interact with the server using a client. On the other hand, a server is a remote computer hosted on a cloud having all the required data and information. Imagine you are working on a complex mathematical problem and you got stuck somewhere and now you picked up the receiver of a telephone dialed a number and called your teacher to ask for the solution. So here the telephone is the client, your teacher is the server, the dialed number is the server address and the way of communication is the API. Now I think that you can relate to all these things.
The request and respose architechture
Once, famous physicist sir, Isaac Newton said that on every action there is an equal and opposite reaction IF you relate these things with real life you will find when you request something from someone you will get a response it may be positive or negative. Imagine you cracked a joke in front of your friends now there are two possibilities either they will laugh or they will reply try something. Similarly, when you send a request to a server you will definitely get a response. like everytime you search something on google you get your desired results.
Talking about the request, it contains a lot of information within it like the headers, our query, the authorization, the data want to search the type of data and many more, these things are just like a visa in our passport which is validated first in the airport then you get the approval.
Again the response contains all the desired results or the information that we have requested from the server, it can be JSON data, flies, images, Html, etc .
The status codes
HTTP status response code or simply status code helps client apps to understand the behavior of a response. These are simple numbers like 200 for success, 201 for resource created 500 for internal server error, etc. While designing an API we use this code to that the one who is using the API can easily understand what is happening on the server side. In simple words status codes are just like grades in mark sheets like A, B, C, etc which helps to understand the efficiency of answers written on the paper.
This was all about API's in simple words make sure to share this article with your peers if you love it and hit the follow buton so you never miss an update from my page.
Checkout my previoes blog here
Top comments (0)