API
The term API is an abbreviation for Application Programming Interfaces. It is a set of definitions and protocols used to develop and integrate application software, enabling communication between two software applications through a set of rules.
Thus, we can speak of an API as a formal specification that establishes how a software module communicates or interacts with another to fulfill one or many functions. All depending on the applications that will use them, and on the permissions given by the API owner to third-party developers.
APIs are never on the surface of a web or application. They are not the visible part, but the internal circuits that only developers see and connect to make a tool work. As we said before, APIs can have both single and multiple functions, and can become real toolkits. When this happens, your application can send it a request with a particular structure, and this structure will determine how the service or software you are sending that request to will respond.
They can be private for a company's use, or public for any developer to interact with or create their own APIs for them to do so. They can also be local APIs for applications that communicate within the same device, or remote APIs for when you need to access a different point.
For services that are not open source, it also allows them to let others use specific functions of their applications or services without having to provide them with all the code. These external developers will be able to use a function without having to know how the processes that make it possible work internally.
What an API is for
One of the main functions of APIs is to make developers' work easier and save them time and money. For example, if you are creating an application that is an online store, you will not need to create from scratch a payment or other system to check if a product is available in stock. You can use the API of an existing payment service, for example PayPal, and ask your distributor for an API that allows you to know the stock they have.
With this, you won't have to reinvent the wheel with every service you create, since you can use parts or functions that others have already created. Imagine if every online store had to have its own payment system, for normal users it is much more convenient to be able to do it with the main services that almost everyone uses.
API REST
is an interface for connecting various systems based on the HTTP protocol and servers to obtain and generate data and operations, returning that data in very specific formats, such as json this can create an HTTP request that contains all the necessary information, that is to say, a REQUEST to a server has all the necessary information and only waits for a RESPONSE, that is to say, a concrete answer. It relies on the basic methods of HTTP, such as:
- Post : To create new resources.
- Get : To obtain a file or a specific resource.
- Put : To modify.
- Patch: To modify a resource that is not a data resource, for example.
- Delete: To delete a resource, a data for example of our database. All the objects are manipulated by means of URI, for example, if we have a
An api must be stateless i.e. each request must contain all the information necessary to be understood by the server, rather than relying on the server to remember previous requests.
Storing session state on the server violates the stateless constraint of the REST architecture. Therefore, session state must be handled entirely by the client.