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

What is RESTful?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly explains "what is RESTful". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is RESTful".

one。 What is RESTful Resource oriented

To put it simply: RESTful is a kind of architectural specifications and constraints, principles, and the architecture that conforms to this specification is the RESTful architecture.

Let's take a look at what REST means. English Representational state transfer declarative state transfer is actually the declarative state transfer of resources.

(what is declarative: it means that the client requests a resource, and the resource obtained by the server is the expression.)

The address of a resource is URL (uniform Resource Identifier) in web.

Resource is the core concept of REST system. All designs are resource-centric.

How to identify resources combined with the project

1. Add goods to the shopping cart

two。 Submit an order

3. Create user user

Add, acquire, modify, delete, and list resources that meet specific criteria around resources. Design interfaces for resources

two。 What are the norms and constraints?

Core specifications and constraints of RESTful Architecture: unified Interface

Divided into four sub-constraints:

1. Each resource has a resource identity, and the resource identity of each resource can be used to uniquely identify the resource.

two。 Self-description of messages

3. The self-description of resources.

4.HATEOAS Hypermedia As The Engine Of Application State (hypermedia as application status engine)

That is, the customer can only get the information needed for the next operation through the information contained in the results returned by the server, such as which URL to send the request to. In other words, a typical REST service does not need additional documentation to indicate which URL accesses a particular type of resource, but rather indicates what operation can be performed on that resource through the response returned by the server.

Purpose: to realize that the client can call all server resources without any documentation.

Third, URL design of resources.

1. Resources are represented by URL

Resources are divided into main resources and sub-resources.

Because the main resource is a class of independent resources, the main resource should be placed directly under the relative path: for example

To represent an instance of the main resource: if the instance is ID=1, this is said: / goods/1

Child resources:

The child resource of an instance may be a collection or a single child resource

The child resource is a collection of pictures: / goods/1/pictures

The sub-resource is the single sub-resource of commodity discount: / goods/1/discount

two。 Singular vs. Complex number

Which way is more consistent with RESTful to get the information of user 1?

/ api/users/1

/ api/user/1

3. Relative path vs. Request parameter

RESTful API of aurora:

Get user information GET / v1/users/ {username} parameters are put in the path

VS

How to get user information by GET / v1/users?username=xxxxx splicing

Get the list of application administrators GET / v1Accord admins administrators start = {start} & count= {count}? The way of post-stitching parameters: this method is generally used as a filtering resource

4. Use the appropriate verb get delete put post

Select the way to request the interface: get delete

PUT updates the resource on the server (the client provides the complete resource after the change).

POST create a new resource on the server

5. Use standard status codes

GET

Safe and idempotent

Get representation

Get representation on change (cache)

200 (OK)-indicates that it has been issued in the response

204 (no content)-indicates that resources are available

301 (Moved Permanently)-the URI of the resource has been updated

303 (See Other)-other (e.g., load balancing)

304 (not modified)-Resource has not changed (cache)

400 (bad request)-refers to a bad request (e.g., parameter error)

404 (not found)-Resource does not exist

406 (not acceptable)-the server does not support the required representation

500 (internal server error)-generic error response

503 (Service Unavailable)-the server cannot currently process the request

POSTPUTDELETE

301 (Moved Permanently)-the URI of the resource has changed

303 (See Other)-other, such as load balancing

400 (bad request)-refers to bad request

404 (not found)-Resource does not exist

409 (conflict)-generic conflict

500 (internal server error)-generic error response

503 (Service Unavailable)-the server cannot currently process the request

200 (OK)-the resource has been deleted

Unsafe but idempotent

Delete a resource

201 (created)-if a new resource is created

301 (Moved Permanently)-the URI of the resource has changed

303 (See Other)-other (e.g., load balancing)

400 (bad request)-refers to bad request

404 (not found)-Resource does not exist

406 (not acceptable)-the server does not support the required representation

409 (conflict)-generic conflict

412 (Precondition Failed)-precondition failure (such as a conflict while performing a condition update)

415 (unsupported media type)-received indication is not supported

500 (internal server error)-generic error response

503 (Service Unavailable)-the service cannot currently process the request

200 (OK)-if an existing resource is changed

Unsafe but idempotent

Create a resource with a client-managed instance number

Update resources by replacement

If it is not modified, update the resource (optimistic lock)

201 (created)-if a new resource is created

202 (accepted)-processing request accepted but not yet completed (asynchronous processing)

301 (Moved Permanently)-the URI of the resource is updated

303 (See Other)-other (e.g., load balancing)

400 (bad request)-refers to bad request

404 (not found)-Resource does not exist

406 (not acceptable)-the server does not support the required representation

409 (conflict)-generic conflict

412 (Precondition Failed)-precondition failure (such as a conflict while performing a condition update)

415 (unsupported media type)-received indication is not supported

500 (internal server error)-generic error response

503 (Service Unavailable)-the service cannot currently process the request

200 (OK)-if existing resources have been changed

Unsafe and non-idempotent

Create a resource using a server-managed (automatically generated) instance number

Create child resources

Partially update resources

If it has not been modified, only update the resource (optimistic lock)

6. Select the appropriate representation structure

Json xml

Thank you for your reading, the above is the content of "what is RESTful", after the study of this article, I believe you have a deeper understanding of what RESTful is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Internet Technology

Wechat

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

12
Report