1. The REST is introduced

REpresentational State Transfer (REST) is an architectural principle that treats Web services as resources that can be uniquely identified by their urls.

A key feature of RESTful Web services is the explicit use of HTTP methods to represent the invocation of different operations.

Basic REST design principles use HTTP protocol methods for typical CRUD operations:

POST – Creates a resource

GET – Retrieves resources

PUT – Updates resources

DELETE – Deletes the resource

The main advantages of REST services are:

They are highly reusable across platforms (Java,.NET, PHP, etc.) because they all rely on the basic HTTP protocol.

They use basic XML instead of complex SOAP XML, which is very convenient to use.

Rest-based Web services are increasingly becoming the preferred approach for back-end enterprise service integration. Its programming model is simple compared to SOAP-based Web services, and the use of native XML (rather than SOAP) reduces the complexity of serialization and deserialization processes and eliminates the need for other third-party libraries that serve the same purpose.

2. Purpose of writing

The purpose of this paper is to make the system functions modular and servitization, and provide users’ operations as services. In order to realize the integration between systems, the interaction between systems is transformed into customized service interaction according to service specification

3. Writing principles

Addressability

Everything in REST is based on the concept of resources. Unlike objects or other nouns in OOP, a resource is an abstraction and must be addressable or accessible through a URI.

Interface Uniformity

Unlike SOAP or other standards, REST requires that the methods or verbs used to manipulate resources are not arbitrary. This means that developers of RESTful services can only use methods supported by HTTP, such as GET, PUT, POST, DELETE, and so on. So there is no need to use a service description language such as WSDL

Statelessness

To enhance scalability, the server side does not store the state information of the client. This keeps the server from being tied to a particular client, making load balancing much easier. It also makes the server easier to monitor and more reliable

Representational

Clients always interact with some representation of a resource, never directly with the resource itself. There can also be multiple representations of the same resource. In theory, any client holding a representation of a resource should have enough information to manipulate the underlying resource.

Connectedness

Any REST-based system should anticipate the client’s need to access related resources and should include these resources in the returned resource representation. For example, you can include related steps in the sequence of operations for a particular RESTful service in the form of hyperlinks, allowing clients to access them as needed.

4. Service instructions

1) Services already provided by the current system




2) Call the service in GET mode




Description:

GET (@requestMapping (value = “treeData”,method = requestmethod.get))

2. Request URL: Specifies the REST service request address, which corresponds to value in the XXXServiceResource

@RequestMapping(value = “treeData”, method = RequestMethod.GET))

3. The GET request contains only the request mode and URL, and the returned result is returned to the client in JSON format

3) Call the service in POST, DELETE and UPDATE mode




Description:

1. Select POST, DELETE, or UPDATE as the request mode (The save favorites function is used as an example (PUT request). @requestMapping (value = “save”,method = requestmethod.put) for each server Resource

2.Json parameters: POST, DELETE, and UPDATE may transfer parameters through Json, or directly join parameters through the path. Here, take transferring Json to the server as an example, corresponding server code:

public JSONObject save(@RequestBody JSONObject obj,BookmarkTag bookmarkTag) {

3. Request URL: Specifies the REST service request URL, which corresponds to value in the XXXServiceResource

@RequestMapping(value = ” save”,method = RequestMethod.PUT))

4. The returned result is returned to the client in JSON format

5. List of services (examples only)

1) Add labels




2) Delete the label




3) Update the label




4) Get the tag list




Welcome to study the relevant technology, source code source