REST
A way to expose your application endpoints
Simple and stateless way to syncronously communicate with services.
It is possible to cache data.
Levels of Maturity
Level 0
Only states that all traffic over HTTP has a purpose to execute a transaction.
(Like do something on DB, or call for execution of a procedure)
There is no level of pattern in it's use.
Level 1
Start using resources.
GET
/products/1
Retrieve Info
POST
/products
Insert
PUT
/products/1
Alter
DELETE
/products/1
Remove
Level 2
When you organize and make sure you use the correct verb for the correct operation, in each URI.
This means for instance, no updates with POST.
Leve 3
HATEOAS (Hypermedia as the Engine of Application State)
Not only awnsers your request, but also, brings others things that you can do from what you just did.
Good Practices
Use unique URIs for each exposed service.
Use the correct
verbsto execute the correct actions.Provide links exemplifying how to use the API.
Response Patterns
Just JSON doesn't provides a hypermedia pattern for responses.
HAL
(Hypermedia Application Language)
Media Type: application/hal+json
In this pattern, besides providing the data from the requested service, it also provides:
_linksthat always tells you the current resource you are accessing. (self).There is also an
_embeddedthat can bring related data from the main data.
Collection+JSON
Siren
Method Negotiation
HTTP has an OPTIONS method. This method allows us to inform which methods are allowed or not in each resource.
Ex.:
OPTIONS anwser could be:
If request sent to this same URI was invalid, like a PUT:
Content Negotiation
The content negotiation process is based on the request the client is doing to the server.
In this case, the user request what and how he wants the anwser to be. The server then might or might not return the request in the desired format.
Accept Negotiation
The client requests the data and the return type, based on a given media type in order of priority.
Ex.:
The anwser could be:
Content-Type Negotiation
Through a content-type in the request header, the server can verify is it will be able to process the data to return.
In case the server doesn't support the content-type it can return:
Last updated