On the RESTful API

RESTful API What is it? Here we give good elaborate on what 

Source: www.yinxiangit.com

REST, namely Representational State Transfer acronym. Directly translated means "the state transformed the presentation layer."
API design is an Internet application:

 URL locate resources, using HTTP verbs (GET, POST, DELETE, DETC) described operation.

 

In recent years, the development of mobile Internet, an endless stream of front-end devices (phones, tablets, desktop computers, other equipment ......), therefore, there must be a unified mechanism to facilitate different front-end and back-end devices to communicate, so RESTful born, it can be through a unified interface to provide services for the Web, iOS and Android.

 

HATE

I.e., a uniform resource identifier, each resource on the server, such as documents, images, video clips, program by a universal resource identifier (Uniform Resource Identifier, referred to as "URI") to locate

HTTP verb

Common HTTP verbs are the following five

  • GET (SELECT): Remove the resource from the server (one or more).
  • POST (CREATE): a new resource on the server.
  • PUT (UPDATE): update the resource (after the complete resources provided by the client to change) in the server.
  • PATCH (UPDATE): Updating Resource (provided by the client to change the properties) in the server.
  • DELETE (DELETE): Delete the resource from the server.

     

RESTful architecture:

Each resource, such as a file server, a picture, a movie, url address has a corresponding, if our clients need for this resource on the server, you will need to perform the appropriate action by the http protocol to operate it, such conduct retrieve, update, delete.

REST is what?

In 2000, one of the principal authors of the HTTP specification Roy T. Fielding published his doctoral thesis with the name. It introduces the concept of REST, and as a well-designed Web applications should be one of the first formal description of what it looks like:

Providing a set of REST architectural constraints, when applied as a whole, and independent deployment of emphasis intermediate components interacting scalability, universal interface assembly to reduce interaction latency, security and packaged embodiments legacy systems.

In the next section, we will detail the concepts and constraints of REST API.

Separation of concerns: the client and the server

All RESTful applications must respect the separation of concerns between the client and the server. This means that the client and the server can fully interoperable. Change the code in the case as long as the client and server agree on the data format (typically JSON) and the messaging protocol (HTTP), can change the client code without affecting the operation of the server, and can not affect the server code clients.

This modularity makes RESTful applications more flexible and easy to expand. Component-oriented development methodology can be used as long as they access the correct REST endpoints, different client and server can interact with each other

 

Heart and soul of RESTful applications is the idea of ​​a uniform interface between components. REST constraints defined by the four interfaces:

Any resource identifier information is resource request, may be named, can, regardless of the type of resource identified by a URI resource.

 

Resources to deal with representation. Representations of these resources are not directly manipulate resources, but throughout the delivery system. HTML, XML, SVG, JSON and PNG format is an example of a resource representation.

Self-descriptive information, each client requests and server responses include all context required to effect the resource.

Basically, each response to allow an operator to provide through URI used to describe each of the API response. Somewhat controversial, many claiming to be a RESTful API to skip this requirement. But to truly RESTful original paper, HATEOAS is a tough requirements.

All in all, there is a unified interface between components, can be implemented with separate service they provide, and encourage independent development. In other words, you achieve interoperability between applications in a distributed network - RESTful API.

Guess you like

Origin www.cnblogs.com/bingerger/p/11516806.html