What is an API?

What is an API?

API stands for Application Programming Interface. But what does it mean?

An API is a way two different software can communicate between them. This communication aims to exchange data, features, and functionality.

This is particularly useful because it makes it easy to collaborate with different people since you can use a service from another team or external to your company.

An example of this could be a payment functionality. Payments are burdensome since an error in the process could make you lose a lot of money, and even in some countries, you have to have a special certification to be able to develop them.

So, some companies specialize in creating this service (like Paypal or Stripe) and offer their products with an API. This allows small teams to have this functionality on their applications.

Where can you find APIs?

They are everywhere. Some examples are:

  • System calls: your operating system has a kernel in charge of communicating with the hardware. So, instead of reinventing what it already has. It gives you ways to communicate with them, such as commands.

  • Library communication: installing a library developed by a third person. You get functionalities and features, sometimes even a way to exchange data. Creating an API allows you to use them on your code easily.

  • Third-system communications: These are communications usually made using HTTP requests. They enable the delegation of tasks to a different system. This is powerful since your company could or could not manage these systems, making it possible for companies to dedicate themselves to what is important to them.

REST API

REST is an acronym for REpresentational State Transfer, the name of an architectural state focused on connecting distributed hypermedia systems.

Like every other architectural style, REST has its own, which an API should follow to be called RESTFUL. These guidelines are

  • Client-server: This is another architectural style where you separate interactions with resources in clients and servers.

    • Clients: These are the ones who need the resources and ask for them without knowing how it

    • Servers: These are the ones who provide the resources and respond to requests from clients to access them

  • Uniform interface: This ensures the representation of resources is represented in a standard way.

  • Stateless: These ensure previous requests don't influence new ones.

  • Cacheable: The server could save the information of a frequent request for a certain period. So it doesn't have to make the process to obtain it again.

  • Layered system: The system should be composed of hierarchical layers that are invisible to the client. In layered systems, each layer cannot see beyond the immediate layer they interact with.

  • Code on Demand (Optional): the ability to send executable code from server to client when requested

WebSocket APIs

These are APIs created based on the WebSocket protocol. This protocol makes for efficient full duplex communication since having this type of communication on HTTP is inefficient.

Full duplex communication creates a channel where two devices can communicate, and both will send information. This is particularly useful for games or messaging apps.

API Gateway

This API accepts all client requests but doesn't process them. Instead, it sends requests to multiple services to respond.

Why would I use this instead of a simple API?

This kind of API is used when you have to process many different requests and you want to divide the responsibilities.

These separations of responsibilities create the following benefits:

  • Reduce complexity

  • Streamline and simplify request processing

  • Simplify troubleshooting