What are API's and how they work

What are API's and how they work

  • What are APIs?

  • API Calls and request

  • Request Methods

  • What is an API key?

  • A real example of an API

  • How do I like to think about API working?

What are APIs?

APIs, or Application Programming Interfaces, play a crucial role in our digital world, facilitating countless digital experiences every minute. An API acts as a middleman, enabling communication between two applications. It takes your request to the provider and delivers the response back to you.

APIs define functionalities independently, allowing for flexibility in implementation without compromising compatibility. They serve as the building blocks that simplify program development.

Developers benefit from the reusability of APIs, sparing them from starting coding projects from scratch. By leveraging APIs, developers can make complex processes reusable with minimal code, significantly expediting their application development.

The IT delivery gap, the divide between business demands and achievable outcomes, is an ongoing challenge. API reuse empowers developers to bridge this gap, scale delivery, and meet business requirements effectively.

API reuse liberates developers from reinventing the wheel each time they embark on a new program or project, as they can draw upon existing APIs, reducing redundancy and enhancing efficiency.

API Calls and request

An API call is when a client application asks a server's API for something. It includes everything that happens after the request is sent, like when the API gets the information from the server and gives it back to the client.

Request Methods

Clients typically make requests to servers to perform basic functions. These requests are often written as URLs, following the rules of the Hyper-Text Transfer Protocol (HTTP) for communication between the client and server. The server can respond to different types of requests using four main methods:

  1. GET: Used to retrieve a specific resource from the server.

  2. POST: Used to create a new resource on the server.

  3. PUT: Used to update or modify an existing resource on the server.

  4. DELETE: Used to remove or delete a resource from the server.

To understand how APIs work, we can use a restaurant analogy (I know is used but is the best way to understand how APIs work).

Imagine you are a customer (client) in a restaurant. The waiter (API) acts as an intermediary between you and the chef (server). You look at the menu (server's available resources), choose the dish you want (make a request), and place your order with the waiter. The waiter then communicates your request to the chef. The chef prepares the meal according to your order (performs the requested operation). Finally, the waiter brings your meal to the table, and you enjoy it without having to cook it yourself.

image source

Now, let's imagine that the restaurant becomes very popular, and more guests start arriving than the available space can accommodate. What can be done in such a situation? This is where API keys come into the picture.

What is an API key?

An API key is a special code (a unique identifier) that is used to verify and authorize requests made to an API. It consists of a combination of letters and numbers that uniquely identifies the client or application making the request. The API key determines whether the request is allowed or denied based on the client's permissions and keeps track of the number of requests made for billing and usage purposes.

Using an API key provides more security than basic authentication, which only requires a username and password.

By requiring clients to have a valid API key, a company can control the number of requests made to their API and ensure that only trusted clients can access their server's resources.

To illustrate this, imagine an API key as a reservation and the API as an exclusive restaurant. Just like the restaurant ensures that only guests with reservations are allowed in, using an API key allows you to limit access to your API's resources to authorized clients. This helps maintain a manageable workload for your server and ensures that requests are handled efficiently and securely.

A real example of an API

How are APIs utilized in practical situations? Let's consider a common example: booking a flight.

When you search for flights online, you have various options to customize your preferences, such as departure and return cities, dates, cabin class, and additional choices like meals, seats, or baggage.

To complete the booking process, you need to interact with the airline's website or a travel service that consolidates information from multiple airlines. This interaction involves accessing the airline's database to check seat availability, pricing based on factors like date, flight time, and popularity of the route.

Regardless of whether you access the information from a website or a mobile phone, you require access to the airline's database. This is where the application interacts with the airline's API, serving as the intermediary between the application and the airline's data.

Similar to a helpful waiter, the API acts as the interface, handling the communication between the application and the airline's systems over the Internet. It retrieves the requested data from the airline and delivers it back to the travel application. This process encompasses various steps, including seat selection, payment, and finalizing the booking.

APIs play a similar role in connecting applications, data, and devices across various interactions. They enable seamless transmission of data between systems, fostering a cohesive experience. APIs offer a standardized approach to access application data or devices, whether it's retrieving information from cloud-based platforms like Salesforce or conducting mobile shopping activities.

How do I like to think about APIs working?

The API's work is something more real than what you think, I have made the API's work clearer when I have understood a thing and I want to share it with you.

APIs are a thing that businesses or other developers, create and share to make their code usable but without knowing how the functionalities are implemented.

Remember this thing, I'd like to think that at a higher level, everything we use every day is an API because you don't know how they are implemented, you only need to know how to request them on a web API you make HTTP request to web server in real life I like to think that we request the object we use with their interfaces.

An example of my vision of API at a higher level could be our smartphone because most people don't know anything about how they work or are implemented, but they know only how to request them to make their interest.

Conclusion

I hope that with this guide and explanation, you could understand better the API concept, I will do other blog posts on API-related uses so please follow the blog and like the post thanks.

Follow and support me:

Special thanks if you subscribe to my channel :)

Did you find this article valuable?

Support Paolo Ferrari by becoming a sponsor. Any amount is appreciated!