当前位置:网站首页>Core concepts of rest

Core concepts of rest

2022-04-23 19:14:00 Li Siwei

REST(Representational State Transfer, Declarative state transitions )

resources

Every standard URL Can uniquely locate web A resource on the server .

When sending HTTP GET When asked , adopt URL To indicate where the resource to be requested is web Where on the server .

Resource expression

When web The client sends HTTP GET After the request , The server responds to the main content of the client , Is the expression of resources .

Every URL The resource being located is unique , However, the expression of resources can be diverse .

for example , For the information of a student stored on the server , The data can be filled into a beautiful... Designed by us HTML On the page , It can also be directly provided to the client for download in the form of plain text file .HTML And text files are different representations of the same resource .

Resource state

For the same URL, Send... At different points in time HTTP GET request , The response of the subject is likely to be different .

for example : At the beginning of class 1 of junior high school, there was 25 A student , The information of these students is managed through the student information management system , If we send a list of all students in class 1 at the beginning of school HTTP GET request , We will get 25 Bar record .
But three weeks after school , A student transferred in and joined class one of grade one , The student's information is also managed into the system . Then we send another URL Exactly the same HTTP GET request , The results are really different : Now the response body contains 26 Student records .

URL Exactly the same , In other words, it is a request for the same resource , But at different points in time , This resource has different states .

Declarative state transitions

The same resource has different states at different time points , When is the state of this resource 、 How did the transfer happen .

The answer is : Three weeks after the start of school, when new students transfer in , Its information is submitted to the management system , At this time , There is one HTTP POST The request is sent to the student information management system server , This request is to submit the information of new students to the system . It's this POST request , Changed the “ Information list of students in class 1 of junior high school ” The state of this resource .

“ Information list of students in class 1 of junior high school ” The state transition of this resource , Is written by a HTTP POST The request resulted in , And this POST Where does the main content of the request come from ? Is submitted from the client HTML Forms , This HTML The form is for the information of newly transferred students HTML describe , That is, the client sends a statement to the server —— New classmate's HTML The form changes the state of the resource ( Transfer )

REST Is a collection of design constraints

REST It's not an agreement 、 Nor is it a development framework , It's a collection of design constraints : No state 、 Using hypermedia as an application state engine .

版权声明
本文为[Li Siwei]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210600381220.html