[REST and RESTful detailed specification] --2019-08-08 21:29:58

Original: http://106.13.73.98/__/60/

RESTful architectural style is a kind of software, design for interactive client and server provides a set of design principles and constraints.
If a framework and principles consistent with the constraints of REST, then we will call it RESTful architecture.
@
***

Web service interactions

  Each site we can see in the browser is a web service. Then we provide with each web service, you need a front and rear side interaction, interaction before and after the end there must be some implementations, we usually call a web service interaction scenarios.

  The three mainstream web service interaction solutions:
  1. REST(Respresentational State Transfer) Representational State Transfer.
  2. SOAP(the Simple Object Access Protocol) Simple Object Access Protocol.
  3. XML-RPC(XML Remote Procedure Call) calls the XML-based Remote Procedure .

XML-RPC is invoked by the function package XML, and HTTP protocol as a transport mechanism.
Later, under the new features are constantly being introduced, this standard SOAP slowly evolved into today's agreement.

SOAP service itself is based on a set of operations defined to access resources on the network.
SOAP is an XML-based, but it is not limited to HTTP transport protocols, including TCP protocol, UDP protocol can transmit.

REST is Dr. Roy Thomas Fielding put forward in his doctoral thesis in 2000.
SOAP REST compared to more compact, performance and efficiency of development also had an outstanding advantage.

Today, we mainly talk about this REST, now more and more began to use REST style web service design and implementation.
For example, amazon.com provide near REST-style Web service to find books; Yahoo Web services also provide REST-style.
***

Understand REST

If we want to understand restful, Representational State Transfer have to first understand the meaning of this phrase - == == representational state transfer.
So-called representational state transfer, in fact, refers to the resource, usually we call == resources state transition ==.

What are the resources?

Anything, as long as it is necessary to be referenced, then it is a resource.

We see in the browser text, images, video, and so are the resources, there really are these entities.

Resources can be an entity, it can be abstract concepts, such as:

  • Kam seek personal information
  • Vulcan's net fire glass
  • Kam seek relations with Vulcan

== in the network, we want to refer to the resources, there must be a logo, a unique identifier of the Web is that URI. ==

URI we do not often hear, we often use the URL, the difference between the two is as follows.

What is URI, URL?

== URI uniform resource identifier ==
== == the URL of a Uniform Resource Locator

Yes, URI is to give us the resources identified, URL is a description of our resources address.

For example, each of us has a name and identity card, the name may be repeated, but I'd be the only one.

Then the ID number can be our URI, identifies each of us, it can be said that each of us to identify resources.
We can find Chang E by ID number, she can also be found by following this way ...

Chang E's address: XX World -> Milky Way -> Orion Arm -> Solar System -> moon ...
This is our URL.

Through these two methods can be found in our resources.

== In fact, we can say that the URL is a subset of URI, URI achieved by positioning ways. ==

This is our Resource Locator, the address with the resources, we are going to access the resource.
So how do we access resources? as follows.

Uniform Resource Interface

We go access to resources through URL, we have a lot of resources to different actions - change search additions and deletions.

Before we could in order to "increase" function, and design a new URL, and the URL will only be responsible for the increase of data, but also for updating and deleting and then were designing a URL.

Now we do, and we just == a URL, and then depending on the HTTP request methods, different operations for resources, this is the Uniform Resource interface. ==

We must follow the way of the semantics of HTTP requests, which means that POST requests in the new data ...

Resource representations

== representation of resources is actually to show the form of resources, are the resources of our client and server transfer of expression, rather than the resource itself. ==

Such as text resources can be used html, xml, json format, PNG or JPG images can be used to show up.

So how do you know which form of client-side presentation services it provides?

HTTP content can be negotiated by the client can request a particular presentation format by Accept header, the server through Content-Type tells the form of representation of client resources.

The expression of these resources is presented on the page, what we call resource status.

State transition

When we look at the page, from the current resource representation (it can be said state or presentation layer) will jump to other state resources.

Tell the customer service end of the agreement by the end of the current status of hypermedia which subsequent state can enter.

Those similar to the "next page" links like this play is to promote the role of the state - under the guidance of a possible state how you enter from the current state.

summary

To conclude, REST-style features are as follows:

  1. In the Web, as long as it is necessary to be quoted, called resources.
  2. Each URI represents a resource, unique.
  3. The client via HTTP methods, server-side resources to operate.
  4. Between the client and the server, passing some kind of presentation layer of such resources.
  5. Through hyperlinks guidelines to achieve "presentation layer state transition."
    ***

    RESTful specification

Resource-oriented programming
: Each URL represents a resource, try not to use the URL verb, noun use.

Depending on the mode of the request, the resources of different operations
: GET / POST / PUT / DELETE / PATCH

Reflected in the URL version
: ·

Whether it is reflected in the URL API
: ·

In the URL filter conditions
: for example: https: / /www.bootcss.com/v1/mycss?page=3

Try using the HTTPS protocol
: For example: https: / /www.bootcss.com/v1/mycss

Response status code is provided
: information 100, the server receives the request, the requester needs to continue.
: 200 successful operation has been successfully received and processed.
: 300 Redirection, further action is required to complete the request.
: 400 Client Error , the request contains a syntax error or not complete request
: 500 server error the server error has occurred during the processing of a request.
: may be a custom state code.

Return Value
: get returns all or a single view of data
: post returns an update of data
: put / patch of data update a return
: delete null return value

API Hypermedia
: If you encounter a situation you want to jump in, please bring a jump interface URL.

is ok.
***

Original: http://106.13.73.98/__/60/

Guess you like

Origin www.cnblogs.com/gqy02/p/11323981.html