Cycle about HTTP part 3
I’m hungry — eats heading HTTP.
So know the principle of operation heading HTTP
What is the REST API?
REST API ( Representational State Transfer) very popular software architecture in IT. Used to connect between two IT systems in specific locations. The very principle of REST API is simple to provide access to particular resources, i.e., data needed for the second IT system.
What does HTTP have to do with the REST API?
HTTP is used for daily communication between systems. It is worth mentioning that as many as 4 HTTP methods are used for communication, here they are:
- GET — displaying all resources or one resource.
- POST — create a new resource. Returning status 201.
- PUT — update of the resource in the database.
- DELETE — deleting a resource in the database.
Specified as CRUD (CREATE — POST, READ — GET, UPDATE — PUT, DELETE — DELETE)
The architectural pattern to be a standard for REST API must use Richardson’s maturity model, which describes the essential elements of the pattern. Richardson’s maturity model is built with four levels, and each standard defines the REST API priority:
Level 0 — remotely calling procedures
- Data transfer via HTTP protocol.
- Converting data in JSON or XML.
- Uses the JSON-RPC protocol.
Level 1 — resources REST API
- Identification of resources using a URI.
- Creating a resource hierarchy using a URI.
Level 2 — methods HTTP
- Using HTTP methods for the REST API pattern.
- Creation of CRUD.
- The level of fulfillment of the requirements for the REST API.
Level 3 — HATEOAS
- This level meets the requirements for RESTful.
- Includes HATEOAS so hypermedia as a mechanism for handling the application status.
- A mechanism for providing the ability to navigate through resources without knowledge of specific URIs.
HATEOAS referred to as Hypertext As the Engine of Application State, additional resource control through hypermedia links not only facilitates access to resources in itself, it has documentation and also optimizes the system code that receives data. The rule is simple, and we get JSON which has a unique _links field in it contains:
- Type — name resources.
- Link — URI to the resource
- Method — the HTTP method that the client should use.
An important element that developers do not pay attention to how to return resources to the client and server. The JSON-RPC standard helps us determine the principle of building resources for all endpoints. For the server:
Customer inquiry:
Variable names:
- Jsonrpc — version of the JSON-RPC specification.
- Id — the query id and the value of the specified resource.
- Method — the name of the method.
- Params — an array of objects to query.
- Result: data returned by calling the method.
- Error-specific error.
In the next cycle will be discussed building a simple REST API in the JSON-RPC standard and building a simple sniffer.
References:
https://martinfowler.com/articles/richardsonMaturityModel.html