Alejandro Veintimilla
Alejandro Veintimilla

Reputation: 11523

What does it mean that REST should be hypertext driven?

I am new to RESTful APIs and everywhere I read that REST APIs "must be hypertext-driven". I have googled a lot but haven't found a concrete explanation of the concept. So:

In practical terms, what does it mean that REST APIs should be 'hypertext-driven'?.

Upvotes: 17

Views: 5252

Answers (2)

nikita
nikita

Reputation: 2817

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

It is about one of the fundamental constraints of REST architectural style - Hypermedia As The Engine Of Application State (HATEOAS). It means that in any given moment, client, based on hypermedia in representation of current resource, must have all the information he needs to decide where to transit next(change its Application State). That hypermedia controls in hypertext connect resources to each other, and describe their capabilities in machine-readable ways. A REST client just needs to know one thing in order to communicate with REST server - understanding of hypermedia. Opposite, in a service-oriented architecture(SOA), clients and servers interact through a fixed interface shared through documentation or an interface description language (IDL).

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

For example,

If you make an initial call to a rest service to add a customer using some URL /customers/ then you will get a response back (consider the customer is successfully added),

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

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

You may ask how does client know that he can make POST to /customer/. By different means - hypermedia controls, DSL specific formats and profiles.

Upvotes: 19

Andre Fonseca
Andre Fonseca

Reputation: 466

REST mean that api follow correct use for HTTP Verbs, Status code, etc. HTTP protocol, has verbs like: GET, POST, PUT, OPTIONS and DELETE. In a rest api, each verb is map to specific action on resource. For example: POST is allways create a new instance of resource; GET is get the resource (or a list), DELETE is allways remove resource associated; PUT is modify/update a exist resource ..... Plus, you should use the status code for indicate response : 201 to create, 200 to modify, etc.

You can take more information on http://restinpractice.com/book/ (Jim Weber book)

Upvotes: -3

Related Questions