Understanding APIs for beginners.
Tags: api, webdev, beginners, programming
Published: 2022-08-15 14:27:42

## APIs
 

Do you sometimes wonder how your phone gets the weather for today or how the time on your laptop updates every time you move to a new country?

Well, guess what? That's the job of an **API**. 
Nice, right ?

## API (Application Programming Interface)
This is a method used to interact between software components and operating systems using a set of rules or protocols.

Using requests and responses, users can communicate with the server through the interface.

How does this work? 

You may be wondering.

Let's jump right into it.

Think of an API as a delivery boy who goes on errands to collect orders, goes back to the shop to give in the orders, and delivers them to you.


The collection of orders is the **request**, while the received orders are called the **response**.


When you need a cup of coffee, you head over to the coffee shop, not the burger shop, even though they are both shops. The same thing applies to APIs. 
We have different APIs for different purposes.

### APIs by Use Cases

**Database API**

If Spotify developers had to write some kind of code every time we needed to listen to a song on their database, there would be no Spotify developers, trust me.

This is the communication between websites or apps and database management systems.
Just as the songs on your Spotify playlist are stored on Spotify’s database, all you need to do is make a request for a song to be played on that playlist by tapping on it and waiting for the response, i.e. the song playing.

**Remote APIs**

This is the way through which apps or websites communicate with the server over a communication network (the internet). 
For this reason, most APIs are designed to meet the web’s specifications.

**The Web API**

This is one of the most commonly used APIs, as it is used by many developers to increase the functionality of the app or website, improve user interactivity, and create a smoother user interface.
Most websites have alternative ways to login, such as logging in with Facebook or Google. This is the Web API in action. A good example of a Web API is the REST API. 


This drives us to our next point.


### APIs by their functions


**SOAP APIs (Simple Object Access Protocols)** 

Here, users and servers communicate via XML.

**RCP APIs (Remote Procedure Calls)** 

When a user completes a procedure on the server, the server sends the data back to the user.

**Websocket API**

This is an API that supports two-way communication. In other words, the user can not only communicate with the server, but the server can also send callback messages, or event-driven responses, to the user. This modern API uses JSON objects to pass in data.

**REST APIs or RESTful APIs** 

These work based on the REST (Representational State Transfer) architectural design (not a set of rules or protocols), but they support functions such as GET, PUT, DELETE, and POST, which users can use to gain access to the server’s data using HTTPS requests via the HTML, JSON, Python, or XML format, etc. 

One of the major highlights of the REST API is **statelessness**. 
This simply means that the storage of information and handling of sessions is the responsibility of the user. In this case, it’s up to you as the user to pass your content to the server. Then this allows the server to store your data and complete your request.

**Benefits of the REST API**

Imagine if the servers had to depend on the user’s input solely before generating an output. This would be a slow process and an inflexible way of building projects. 
Thankfully, the REST API helps users and servers work independently, as the REST protocol separates the database management system from the server. This helps developers build independently and test various work environments.

Due to the independence of user and server, the REST API can be scaled rapidly.
REST APIs help a lot with integrations, as you don’t need to build code from scratch. 

What are integrations?

### API Integrations
These are software components that modify data between the user and the server without any change to the previous contents. Just as your pictures get synced from the cloud, this is where API integrations come in. All the developer needs to do is to integrate an API of whatever project into his code, and ta-da!!

### APIs by Access

**Private API**

This API is only accessible by members of an organization.

**Public API**

This API is open to members of the public, but some kind of authorization may be required or fees may be attached to it.
This is a good way to make money from making APIs.

**Partner API** 

This API is only open to authorized developers who are linked to this API via business.

**Composite API**

Imagine sending 50 requests to an API, then the server has to run each request individually. This will be a sluggish and inefficient process. Well, that’s why composite APIs were designed to handle requests in batches instead of individually, as this saves time and helps efficiency.

The end!

Please don't hesitate to drop a comment and share if it was helpful!