What does it mean that REST should be hypertext oriented?

I'm new to the RESTful API, and I read everywhere that the REST API "must be hypertext based." I googled a lot, but did not find a specific explanation for the concept. So:

From a practical point of view, what does the REST API have to be "hypertext"?

+5
source share
2 answers

When I say hypertext, I mean the simultaneous presentation of information and controls such that the information becomes the affordance through which the user (or automaton) obtains choices and selects action. Roy T. Fielding - http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven

This is one of the main limitations of the REST architecture - Hypermedia as the Engine of Application State (HATEOAS for short). This means that at any moment the client, based on hypermedia in the presentation of the current resource, must have all the information he needs to decide where to go next (change his application state). This hypermedia controls the linking of resources to each other in hypertext and describes their capabilities in machine-readable methods. The REST client just needs to know one thing to communicate with the REST server - understanding hypermedia. In contrast, in a Service Oriented Architecture (SOA), clients and servers interact through a fixed interface, shared by documentation or an interface description language (IDL).

HATEOAS separates the client and server so that they can be developed separately.

For instance,

If you make an initial call to the recreation service to add a client using any URL / clients /, you will receive a response (think that the client was successfully added),

 HTTP/1.1 201 Created Location: http://www.myREST/customers/<uuid>/ 

Now the client who made the call to add the client knows how to find the corresponding client from the link returned as the response header.

You may ask how the client knows what he can do POST / to client /. Using various tools - hypermedia controls, special formats and DSL profiles.

+10
source

REST means that api should be used correctly for HTTP verbs, status code, etc. The HTTP protocol has verbs such as GET, POST, PUT, OPTIONS, and DELETE. In rest api, each verb is a map for a specific action on the resource. For example: POST always creates a new instance of the resource; GET receives the resource (or list), DELETE always deletes the associated resource; PUT modifies / updates an existing resource ..... In addition, you must use the status code to indicate the response: 201 to create, 200 to change, etc.

You can get more information about http://restinpractice.com/book/ (Jim Weber book)

0
source

Source: https://habr.com/ru/post/1204783/


All Articles