What is an API?
API (Application Programming Interface) is an interface/intermediate software that allows two different applications to talk to each other.
WWW and Remote Servers
- A WWW (World Wide Web) is about communication between Clients and Servers
- Clients are browsers.
- Servers are database/backend of the websites.
- Every page on the internet is stored somewhere on a remote server.
- When you hit www.perficient.com in a browser, a request goes out to Perficient’s remote server and it sends back the required response to the browser.
- As a result, the browser interprets the code and displays the page.
Request, Response, and API:
Pretend you’re at a table in a restaurant, with a menu in front of you.
In the kitchen, food will be prepared.
So, how are you going to order your food and have it delivered to you from the kitchen?
WITH THE HELP OF WAITER…..
Your order is referred to as a Request.
API is the Waiter.
The kitchen is the server.
The Response is the order/food from the kitchen.
- Instead of ordering food, order a mobile in a restaurant.
- The Waiter/Kitchen will deny your order (request).
- You will get only food in a restaurant not mobile.
- You will get the proper response if and only if it is available on the server otherwise will get errors or failures.
- Sometimes you order the correct food, but the waiter/server still denies your request because of particular reasons they are not able to prepare that food.
Exercise to understand the working of API:
- Enter www.perficient.com or any other website you are familiar with into your browser.
- Take note of how the page loads and displays a Google homepage within a fraction of a second.
- That means our request was proper, and we received a proper response.
- Now, in the browser, type www.perficient.google.
- It will display an error message.
Choosing a Global Software Development Partner to Accelerate Your Digital Strategy
To be successful and outpace the competition, you need a software development partner that excels in exactly the type of digital projects you are now faced with accelerating, and in the most cost effective and optimized way possible.
- Hyper Text Transfer Protocol.
- Sending an HTTP request and receiving an HTTP response are the Communications between Client and Servers.
- Example: https://api.publicapis.org/entries?category=animals&cors=yes
Host: It can be any website.
Resourcepath: It’s similar to a directory or folder structure that contains data.
Requested parameters: It is a query that is used to retrieve sorted data from a server.
So, it will return data related to animals only, if and only if the value of ‘cors’ in the response is set to ‘yes’.
Every API made to the server, uses following types of methods –
- GET – To retrieve data from the server.
- POST – To add new data/resource into the server.
- PUT – To update the existing data in the server.
- DELETE – To delete the data/resource from the server.
HTTP Status Codes:
When we receive a response, it contains some status code:
200: OK – The request was successful and we have got the requested data in the Response.
500: Internal Server Error – Because the server has run into an issue so, it is unable to resolve it.
404: Not Found – The server is unable to locate the requested resource.
401: Unauthorized – The requested resource requires authorization or you are using the incorrect credentials.
And more ………
“Anyone who stops learning is old, whether at twenty or eighty.”
— Henry Ford