Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Jeesz distributed Architecture-RestFul Services

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Summary: REpresentational State Transfer (REST) is an architectural principle that treats web services as resources that can be uniquely identified by their URL. A key feature of RESTful Web services is the explicit use of HTTP methods to represent invocations of different operations. The basic design principles of REST use the HTTP protocol method for typical CRUD operations: POST-create resource GET-retrieve resource PUT-update resource DELETE-delete resource REST service the main advantages are:

1. REST introduction

REpresentational State Transfer (REST) is an architectural principle that treats a web service as a resource that can be uniquely identified by its URL.

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

The basic design principles of REST use the HTTP protocol approach for typical CRUD operations:

POST-create a resource

GET-retrieve resources

PUT-Update Resources

DELETE-Delete a 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 and are very convenient to use.

REST-based web services are increasingly becoming the preferred method for back-end enterprise service integration. Compared with SOAP-based web services, its programming model is simple, and the use of native XML (rather than SOAP) reduces the complexity of the serialization and deserialization process, and eliminates the need for other third-party libraries that do the same.

two。 Purpose of compilation

The purpose of writing this article is to modularize and service the system function, and provide the user's operation in the way of service. The interaction between the system and the system follows the service specification, and the interaction between the system and the system is transformed into customized service interaction, so as to realize the integration between the system and the system.

3. Compiling principle

Addressability (Addressability)

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

Interface consistency (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. Therefore, there is no need to use service description languages such as WSDL.

Stateless (Statelessness)

To enhance scalability, the server does not store the state information of the client. This makes the server unbound to a specific client and makes load balancing much easier. It also makes the server easier to monitor and more reliable

Representation (Representational)

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

Connectivity (Connectedness)

Any REST-based system should foresee that the client needs to access the relevant resources and should include these resources in the returned resource representation. For example, you can include the relevant steps in the sequence of operations of a particular RESTful service in the form of a hyperlink so that clients can access them as needed.

4. Service usage instructions

1) the services already provided by the current system

2) call the service in GET mode

Description:

1. The request method includes: GET (here take area service as an example, and GET corresponds to @ RequestMapping in each service Resource (value = "treeData", method = RequestMethod.GET))

two。 Request URL:rest service request address, corresponding to value in XXXServiceResource.java 's mapping configuration

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

3. The GET request only contains the request method and the request 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 and UPDATE for the request method (here, take saving favorites function as an example (PUT request), corresponding to @ RequestMapping in each Resource (value = "save", method = RequestMethod.PUT))

2.Json parameters: where POST, DELETE, and UPDATE may pass parameters through json, or they may be stitched directly through paths. Here, we take passing json to the server as an example, corresponding to the server code:

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

3. Request URL:rest service request address, corresponding to value in XXXServiceResource.java 's mapping configuration

@ 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 tags

2) Delete tags

3) Update the label

4) get the tag list

Welcome to study and study related technologies together.

Friends who are willing to understand the framework technology or source code directly ask (Penguin): 2042849237

For more details, source code reference: http:// × × / technology

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report