Concepts

REST, or Representational State Transfer, is an architectural style for API interactions over HTTP. It is an application-level standard for the communication between the client and the server and is characterized by statelessness and clear client-server separation of concerns.

The key abstraction in this style is that of resource, which can be anything: a document, a ticket, a user, a collection of other resources, and so on. In a RESTful service, the interface consists of a hierarchical set of resources and methods defined for each of them to enable state transfer. Each resource has an unique ID, which identifies it. The transfer can be from the server to the client (get information) or from the client to the server (set information). The GET HTTP verb is analogous to what happens when a person clicks a link on a website. The entire content at the URL, which describes that object, is transferred from the server to the client and rendered in the browser.

Nearly all RESTful APIs use HTTP as a transport layer. Each resource gets a Uniform Resource Identifier (URI). The HTTP verbs such as GET, POST, PUT, DELETE, and PATCH serve as methods on the resource.

For example, the following is a simplified API example for hotels:

URI

Verb

Meaning

/hotels

GET

Get a list of all hotels on the website. At a minimum, this would typically be a JSON array with a tuple for each hotel, including the URI of the hotel, a unique ID, and probably the display name.

/hotels

POST

Creates a new hotel. Will take all the attributes needed to create a new hotel.

/hotels/<id>

GET

Get information (all attributes) about a specific hotel, whose identifier is <id>.

/hotels/<id>

DELETE

Delete the hotel with the specified ID.

/hotels<id>

PUT

Updates the attributes of a hotel. Takes the same parameters as create (POST).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset