To communicate with other software system, we must always follow the rules. An API (Application Programming Interface) is here to define the rules to follow. Usually, developers design APIs so that programmes may interact programmatically with one another. In the simplest terms, you ask the system to do something, and it gives you the results. A web API can be best understood as a gateway between clients and web resources.
Users that seek to obtain information via the web are referred to as clients. The client, who makes use of the API, might be a human or a software application. For example, developers write a program that accessing the data from a system, you can now access to the same data from your browser when you visit the website directly. For resources, it is the information from different applications to their clients. Images, table, text, videos, charts and more can be resources. The device that provides the client with the resource is sometimes referred to as the server. While ensuring security, control, and authentication, businesses utilise APIs to share resources and offer online services. They may also choose which customers have access to particular internal resources with the use of APIs.
A software architecture called Representational State Transfer (REST) places restrictions on how an API should operate. The reason of using REST is because it taking advantage of the HTTP. From this point of view, developers do not need to install additional software or libraries while creating REST API. Scalable, high-performing, and reliable communication is supported by REST. It is simple to implement and adapt, giving any API system visibility and cross-platform compatibility. REST can also support a variety of call types, return diverse data formats, and even alter architecturally with the proper implementation of hypermedia since data is not linked to resources or functions. By using REST, GET, POST, PUT and DELETE is used easily with a single command. APIs may be created by developers using a variety of architectures. REST APIs are the name given to APIs that adhere to the REST architectural design. RESTful web services are web services that use the REST architecture. RESTful web APIs are commonly referred to as RESTful APIs.
The explanation for each action is describe in table below.
Actions |
Explanation |
GET | To get a list of resources |
POST | To create a new resource |
PUT | To update the resource |
DELETE | To delete the resource |
By using http://example.com/fruit as an example.
Actions |
Example domain |
Explanation |
GET | http://example.com/fruit | Get a list of resources |
POST | http://example.com/fruit | To create a new resource |
GET | http://example.com/fruit/id=1 | To get the resource with id 1 |
PUT | http://example.com/fruit/id=1 | To update the resource with id 1 |
DELETE | http://example.com/fruit/id=1 | To delete the resource with id 1 |
By using the client and resource above, when the request is made via RESTful API, it transfers a representation of the state of the resource to the requester or endpoint. One of various forms, including JSON (Javascript Object Notation), HTML, XLT, Python, PHP, or plain text, is used to send this information or representation through HTTP. At the same time, in the HTTP methods of a RESTful API HTTP request, headers and parameters are also necessary since they provide essential identification information about the request's metadata, authorisation, unified resource identifier (URI), caching, cookies, and more. There are headers for requests and responses, and each one contains information about the HTTP connection and a status code.
Example of the headers.
Headers |
Example |
Request |
|
Responce |
|
Representation |
|