Understanding REST
来源:互联网 发布:淘宝肉妈护肤品扒皮 编辑:程序博客网 时间:2024/06/14 00:45
原文链接: https://spring.io/understanding/REST
Understanding REST
REST (Representational State Transfer) was introduced and defined in 2000 by Roy Fielding in his doctoral dissertation. REST is an architectural style for designing distributed systems. It is not a standard but a set of constraints, such as being stateless, having a client/server relationship, and a uniform interface. REST is not strictly related to HTTP, but it is most commonly associated with it.
Principles of REST
- Resources expose easily understood directory structure URIs.
- Representations transfer JSON or XML to represent data objects and attributes.
- Messages use HTTP methods explicitly (for example, GET, POST, PUT, and DELETE).
- Stateless interactions store no client context on the server between requests. State dependencies limit and restrict scalability. The client holds session state.
HTTP methods
Use HTTP methods to map CRUD (create, retrieve, update, delete) operations to HTTP requests.
GET
Retrieve information. GET requests must be safe and idempotent, meaning regardless of how many times it repeats with the same parameters, the results are the same. They can have side effects, but the user doesn't expect them, so they cannot be critical to the operation of the system. Requests can also be partial or conditional.
Retrieve an address with an ID of 1:
GET /addresses/1
POST
Request that the resource at the URI do something with the provided entity. Often POST is used to create a new entity, but it can also be used to update an entity.
Create a new address:
POST /addresses
PUT
Store an entity at a URI. PUT can create a new entity or update an existing one. A PUT request is idempotent. Idempotency is the main difference between the expectations of PUT versus a POST request.
Modify the address with an ID of 1:
PUT /addresses/1
Note: PUT replaces an existing entity. If only a subset of data elements are provided, the rest will be replaced with empty or null.
PATCH
Update only the specified fields of an entity at a URI. A PATCH request is idempotent. Idempotency is the main difference between the expectations of PUT versus a POST request.
PATCH /addresses/1
DELETE
Request that a resource be removed; however, the resource does not have to be removed immediately. It could be an asynchronous or long-running request.
Delete an address with an ID of 1:
DELETE /addresses/1
HTTP status codes
Status codes indicate the result of the HTTP request.
- 1XX - informational
- 2XX - success
- 3XX - redirection
- 4XX - client error
- 5XX - server error
Media types
The Accept
and Content-Type
HTTP headers can be used to describe the content being sent or requested within an HTTP request. The client may set Accept
to application/json
if it is requesting a response in JSON. Conversely, when sending data, setting the Content-Type
to application/xml
tells the client that the data being sent in the request is XML.
- Understanding REST
- Understanding REST
- Understanding and Using the SharePoint 2013 REST Interface
- Understanding
- rest
- rest
- REST
- REST
- REST
- rest
- REST
- REST
- rest
- rest
- REST
- REST
- REST
- REST
- 决策树、随机森林、GBDTxgboostfastRGF 学习笔记
- springmvc对集合参数绑定时:参数的命名
- 前端模板引擎artTemplate---高性能JavaScript模板引擎
- 折腾MySQL,遇到的问题
- PEP8 indentation写法
- Understanding REST
- 编码过滤器,过滤中文乱码(Post和get方式都支持)
- 利器系列-为Tomcat添加User 像easyPHP那样使用Manager App高效管理你的应用
- 关于AJAX跨域调用ASP.NET MVC或者WebAPI服务的问题及解决方案
- linux使用中出现的小问题汇总(持续更新)
- opencv 根据模板凸包求阈值化后的轮廓组合
- chown
- Java处理http协议相关初步(一)——httpclient
- Java的四种访问修饰符