当前位置:网站首页>2021.9.29 learning log restful architecture
2021.9.29 learning log restful architecture
2022-06-13 05:39:00 【kaesarsk】
restful framework
CSDN Reference resources
restful Is a constraint of Architecture , A constraint criterion is given .
REST:Representational State Transfer( The transformation of the state of the image layer ):
1. every last URI Represents a resource ;
2. Between client and server , A layer of expression that conveys this resource ;
3. Client through four HTTP Verb (get、post、put、delete), Operate on the server-side resources , Realization ” Represent layer state transformation ”.
REST Architecturally 6 Great principles
1. C-S framework
The data is stored in Server End ,Client Just use the end . The advantage of a complete separation of the two ends makes client The portability of the end code becomes stronger ,
Server The expansion of the end becomes stronger . Both ends are developed separately , Mutual interference .
2. No state
http The request itself is stateless , be based on C-S framework , Every request from the client has enough information to be recognized by the server .
Some of the information required for the request is contained in URL The query parameters of 、header、body, The server can request various parameters according to , No need to save the state of the client ,
Return the response to the client correctly . Stateless features greatly improve the robustness and scalability of the server .
Of course, this total stateless constraint also has disadvantages , Each request from the client must carry the same repeated information to determine its identity and status ( This is also necessary ),
Cause redundancy of transmission data , But this disadvantage is important for performance and use , Almost ignored .
3. Unified interface
That's it REST The heart of the architecture , A unified interface for RESTful Service is very important . The client only needs to pay attention to the implementation interface , The readability of the interface is enhanced , It is convenient for users to call .
4. Consistent data format
The data format returned by the server is either XML, Or Json( get data ), Or directly return the status code
Self describing information , Each data should be self describing , It is convenient for the code to process and parse the content .
Such as through HTTP The returned data contains [MIME type ] Information , We from MIME type You can know the specific format of the data , It's a picture. , Video or JSON,
Client pass body Content 、 Query string parameters 、 Request the head and URI( Resource name ) To transmit state . Server through body Content , The response code and response header are sent to the client .
This technology is called hypermedia ( Or hypertext links ).
In addition to the above ,HATEOS Also means that , Links can also be included in the returned body( Or the head ) in , In order to provide URI To retrieve the object itself or the associated object .
If you ask for a tweet , The server response information should include other information related to this Weibo URL, The client can further utilize these URL Initiate a request for information of interest , Another example is that paging can get the next page's data from the return data of the first page URT It's also based on this principle .
JSON For example :
code—— Containing an integer type HTTP Response status code .
status—— Include text :”success”,”fail” or ”error”.HTTP The status response code is 500-599 Between for ”fail”, stay 400-499 Between for ”error”,
Others are ”success”( for example : The response status code is 1XX、2XX and 3XX). According to the actual situation, this is not necessary .
message—— When the state value is ”fail” and ”error” Effective when , Used to display error messages . Refer to internationalization (il8n) standard ,
It can contain information numbers or codes , Can contain only one of , Or include and separate with separator at the same time .
data—— Containing the response body. When the state value is ”fail” or ”error” when ,data Contains only the error cause or exception name 、 perhaps null It's OK, too
Return a successful response JSON:
{
"code": 200,
"message": "success",
"data": {
"userName": "123456",
"age": 16,
"address": "beijing"
}
}
Return the failed response json Format :
{
"code": 401,
"message": "error message",
"data": null
}
4. System layering
The client is usually unable to indicate whether it is directly or indirectly connected to the end server , The security policy should also be considered when layering
5. Caching
On the World Wide Web , The client can cache the response content of the page . So the response should be implicitly or explicitly defined as cacheable ,
If it is not cacheable, the client should avoid using old data or dirty data to respond after multiple requests .
Properly managed cache will partially or completely remove the interaction between client and server , Further improve performance and ductility .
6. On demand coding 、 Customizable code ( Optional )
The server can choose to temporarily send some function codes to the client for execution , To customize and extend some functions of the client .
For example, the server can return some Javascript The code lets the client execute , To achieve certain functions .
Tips :REST Design criteria in Architecture , Only on-demand coding is optional . If a service violates any other criterion , Strictly speaking, it can't be called RESTful style .
边栏推荐
- Case - recursive factorial (recursive)
- Std:: map insert details
- Randomly fetch data from the list
- COAP protocol libcoap API
- 13 cancelendevent of a flowable end event and compensationthrowing of a compensation event
- Jeffery0207 blog navigation
- 9. Errorstartevent and errorboundaryevent of error events
- Summary of the 11th week of sophomore year
- Case - the ArrayList collection stores student objects and traverses them in three ways
- Float type value range
猜你喜欢

Quartz basic use

安装harbor(在线|离线)

Enhanced for loop

Install harbor (online offline)

Comment procéder à l'évaluation des algorithmes

OpenGL马赛克(八)

Getclassloader() returns null, getclassloader() gets null

Basic operations of MySQL auto correlation query

KVM hot migration for KVM virtual management

A simple recursion problem of linked list
随机推荐
mongo
Violence enumeration~
OpenGL马赛克(八)
Fast power code
Mongodb Multi - field Aggregation group by
Anaconda configuring the mirror source
MySQL transactions and foreign keys
计算两个时间相差的天数(支持跨月、跨年)
Input a number and output each digit from high to low
使用cmake交叉编译helloworld
Solution to prompt "permission is required to perform this operation" (file cannot be deleted) when win10 deletes a file
Initial redis experience
MySQL installation in Linux Environment
【转载】C语言内存和字符操作函数大全
NVIDIA Jetson Nano/Xavier NX 扩容教程
Error: unmapped character encoding GBK
KVM virtualization management tool
RT thread console device initialization
20 flowable container (event sub process, things, sub process, pool and pool)
float类型取值范围