E
REST is one of the almost-programistic things that explains more than anything in the world. It's not gonna be a full explanation, but just an example. Well, unfortunately, I just can't.You must have met the Representational State Transfer. If it's rude, it's a clear HTTP version of the application. In general, it's just the concept of processing the interface for API clients.Let's pretend that some store has decided to start its API. To this end, the programmer provided a sub-distance. http://api.maga.zin/v1 and invites everyone to send requests there:POST http://api.maga.zin/v1 HTTP/1.1
{
"action": "getProducts",
"parameters": {
"page": 3,
"size": 50,
"sort": [ {
"field": "price",
"direction": "asc"
} ]
}
}
Although this thing can work, it won't be automated at all. What kind of operation goes outside - reading, updating, creating or removing? Can I repeat it? What resource is it? Can a home area of error be easily recalibrated if it occurs? All questions can be answered negatively, even those that do not imply a boulder response; this is API zero REST or API, which has nothing to do with REST.However, this example is exhausted from the finger. More often than not, URL can determine what work is being done, for example, the same contact with his audio.get provides an opportunity to determine that the client will receive the audio data. This is the first level of maturity of REST - the breakdown of API by individual resources with which work is carried out. Normally, resources are broken differently:/audio - collection audio recordings/audio/1234 - separate audio recording resource with identifier 1234Here, I want to stop for a little while, and I want to point out that the work (in the right API) is not being done as an urn for which data can be obtained, but with two resources♪ Column filtering♪ disorientation and get it. Separate extraction (straight) to create a new element (new separate resource), in a number of cases, replace or dispose of the entire resource, and a specific resource can be obtained (possibly also with filtering, if larger), replace or delete.In the context of the example of a shopping shop, requests may already look like:POST http://api.maga.zin/v2/product?act=edit&id=12 HTTP/1.1
{
"name": "Иисусья тряпка",
"price": 123,
"quantity": 12
}
However, the very breakdown of resources does not fully distinguish one operation from another. For this, REST proposes to use HTTP-methods: POST (create), GET (read), PUT (update), DELETE. If used, the request clearly informs the server what it wants: GET /account/123 means the need to obtain the Accaunt resource with the identifier 123, DELETE /countac means the need to remove all available accountants. The use of HTTP-methods is REST 2. When you hear about REST API, you are most likely to be told about this case-- about the allocation to resources and the transfer of a specific operation through HTTP-method.And finally, there's a third level of ripeness REST, but it's virtually nowhere to be used. At this level, API provides not only resources but also clues on the management of these resources. If you submit the following leaflet:/pair?page=12&size=2
[
{
"x": 12,
"y": 13
},
{
"x": 25,
"y": 26
}
]
It's totally unspontaneous, as you're referring to a couple. {"x": 12, "y": 13}to remove it; it is also unclear what page it is, whether there is a next one, and how to proceed to the previous one. Therefore, API provide these data:/pair?page=12&size=2
{
"content": [
{
"x": 12,
"y": 13,
"link": "/pair/12-13"
},
{
"x": 25,
"y": 26,
"link": "/pair/25-26"
}
],
"pagination": {
"currentPage": 12,
"nextPage": null,
"previousPage": "/pair?page=11&size=2",
"totalPages": 12,
"totalElements": 24
}
]
REST does not specify how these clues should be made, but there is widespread use http://stateless.co/hal_specification.html + ALPS to describe the API itself (i.e. to describe which resources and address are located). These clues allow a client - man or programme - to discover resources without knowing their existence at the time of request.Is that what REST is? REST is the paradigm of API, which implies (among other things) a clear breakdown of resources and the challenge of the operation by means of a specific HTTP method. But, only within this story and overflows of a purely webdeveloperic character: strictly speaking, REST is http://www.restapitutorial.ru/lessons/whatisrest.html which makes it necessary to work in this way. But when you see the REST API on the Internet, it's about a clear division of resources, HTTP-method operations, the right Content-Type, depending on the Acceptance, the expression of errors through HTTP codes and the uniformity of presentation of those resources.
And the souffix (which is actually ful rather than full) means only the conversion of the word into an adjective, REST is a paradigm, RESTful API - API, corresponding to the paradigm.What does she even give? First, the API is getting fresh, and it smells good - easy and easy to work with, because you know that he's gonna expect resources to always be presented in the same way, and you know it's not just you, but any API client. develop api-client without the knowledge of final resources); second, this logic refers not only to the specific API, but also to all API built in the REST paradigm. Therefore, once learning from API github will not work with any other REST API.In case I started writing too general and humanitarian, additional references: https://habrahabr.ru/company/hexlet/blog/274675/ http://martinfowler.com/articles/richardsonMaturityModel.html