Apis
Apis
An API, which stands for application programming interface, is a set of protocols that enable
different software components to communicate and transfer data. Developers use APIs to bridge
the gaps between small, discrete chunks of code in order to create applications that are powerful,
resilient, secure, and able to meet user needs
APIs allow different software applications to communicate with each other, They are used to
retrieve data or perform actions, such as creating records or updating existing ones.
The following are the six REST design principles, also known as architectural
constraints :
1. Uniform interface: All API requests for the same resource should look the same, no
matter where the request comes from. The REST API should ensure that the same piece
of data, such as the name or email address of a user, belongs to only one uniform resource
identifier (URI). Resources shouldn’t be too large but should contain every piece of
information that the client might need.
2. Client-server decoupling: In REST API design, client and server applications must be
completely independent of each other. The only information the client application should
know is the URI of the requested resource; it can’t interact with the server application in
any other ways. Similarly, a server application shouldn’t modify the client application
other than passing it to the requested data via HTTP.
3. Statelessness: REST APIs are stateless, meaning that each request needs to include all the
information necessary for processing it. In other words, REST APIs do not require any
server-side sessions. Server applications aren’t allowed to store any data related to a
client request.
4. Cacheability: When possible, resources should be cacheable on the client or server side.
Server responses also need to contain information about whether caching is allowed for
the delivered resource. The goal is to improve performance on the client side, while
increasing scalability on the server side.
5. Layered system architecture: In REST APIs, the calls and responses go through different
layers. As a rule of thumb, don’t assume that the client and server applications connect
directly to each other.
6. Code on demand (optional): This constraint allows clients to download and execute code
from servers.
Any REST request includes four essential parts: an HTTP method, an endpoint, headers, and a
body.
An HTTP method describes what is to be done with a resource. There are four basic methods also
named CRUD operations:
• POST to Create a resource,
• GET to Retrieve a resource,
• PUT to Update a resource, and
• DELETE to Delete a resource.
An endpoint contains a Uniform Resource Identifier (URI) indicating where and how to find the
resource on the Internet. The most common type of URI is a Unique Resource Location (URL),
serving as a complete web address.
Headers store information relevant to both the client and server. Mainly, headers provide
authentication data — such as an API key, the name or IP address of the computer where the
server is installed, and the information about the response format.
A body is used to convey additional information to the server. For instance, it may be a piece of
data you want to add or replace.
In response, the server sends not the sought-for resource itself, but its representation — a
machine-readable description of its current state. The same resource can be represented in
different formats, but the most popular ones are XML and JSON.
Whenever relevant, a server includes in the response hyperlinks or hypermedia that links to
other related resources. This way, the server gives instructions on what the client can do next
and what further requests it can make.