当前位置:网站首页>Restful interface specification
Restful interface specification
2022-07-26 22:42:00 【Everything is lovely 33】
1.Restful
REST The full name is Representational State Transfer, Chinese means to express ( Editor's note : Representational state transition )
RESTful It's a definition Web API Interface design style , It is especially suitable for the application mode of front and rear end separation . The idea of this style is that the back-end development task is to provide data , What we provide externally is the access interface of data resources , So when defining interfaces , Client access URL The path represents the data resource to be operated . in fact , We can use any framework to achieve compliance with restful canonical API Interface . RESTful As the most popular API design code , It must have its unique charm : Powerful 、 brief introduction 、 Easy to use
2.Restful Ten interface specifications of
# 10 Rules
1. Data security :
url Links are generally used https Protocol for transmission notes : use https agreement , It can improve the security in the process of data interaction2. Interface feature representation , You know it's a api Interface
- use api Keyword identification interface url:
- [https://api.baidu.com](https://api.baidu.com/)
- https://www.baidu.com/api
notes : notice api The word , On behalf of the request url The link is to complete the data interaction between the front and back stations
- Luffy's interface :https://api.luffycity.com/api/v1/course/free/3. Multiple data versions coexist
- stay url The link identifies the data version
- https://api.baidu.com/v1
- https://api.baidu.com/v2
notes :url In the link v1、v2 It's the embodiment of different data versions ( Only when a data resource has multiple versions : For example, add interfaces to the original version , Similar revision , You also need to ensure that the old version can be used )4. Data is a resource ( They all use nouns )
The interface is generally used to complete the data interaction between the front and the back , Interactive data is called resource
https://api.baidu.com/users
https://api.baidu.com/books
https://api.baidu.com/book
notes : It is generally advocated to use the plural form of resources , stay url Do not use verbs to operate resources in links , Error model :https://api.baidu.com/delete-user
A special interface can have Verbs , Because these interfaces generally do not have a clear resource , Or the verb is the core meaning of the interface
https://api.baidu.com/place/search
https://api.baidu.com/login5. Resource operation is determined by the request mode (method)
- Operating resources usually involves adding, deleting, modifying and querying , We provide a request method to identify the addition, deletion, modification and query actions
- https://api.baidu.com/books - get request : Get all books
- https://api.baidu.com/books/1 - get request : Get the primary key as 1 The book of
- https://api.baidu.com/books - post request : Add a new book
- https://api.baidu.com/books/1 - put request : Change the primary key as a whole to 1 The book of
- https://api.baidu.com/books/1 - patch request : Change the primary key to 1 The book of
- https://api.baidu.com/books/1 - delete request : Delete the primary key as 1 The book of6. Filter , By means of url Pass search terms in the form of upload parameters
- https://api.example.com/v1/zoos?limit=10: Specify the number of returned records
- https://api.example.com/v1/zoos?offset=10: Specify where to start the return record
- https://api.example.com/v1/zoos?page=2&per_page=100: Specify page , And the number of records per page
- https://api.example.com/v1/zoos?sortby=name&order=asc: Specifies which attribute to sort the returned results by , And sort order
- https://api.example.com/v1/zoos?animal_type_id=1: Specify filter criteria7. Response status code
7.1 Normal response
- Response status code 2xx
- 200: Regular requests
- 201: Create success
7.2 Redirect response
- Response status code 3xx
- 301: Permanent redirection
- 302: Redirect temporarily
7.3 Client exception
- Response status code 4xx
- 403: Request no permission
- 404: The request path does not exist
- 405: The request method does not exist
7.4 Server exception
- Response status code 5xx
- 500: Server exception8. Error handling , Error message expected ,error treat as key
{
error: " No permission to operate "
}9. Return results , For different operations , The results returned by the server to the user should conform to the following specifications
GET /collection: Returns a list of resource objects ( Array )
GET /collection/resource: Return a single resource object
POST /collection: Return the newly generated resource object
PUT /collection/resource: Returns the complete resource object
PATCH /collection/resource: Returns the complete resource object
DELETE /collection/resource: Return an empty document10. need url Requested resources : Request links that require access to resources
# Hypermedia API,RESTful API Better do Hypermedia, That is, the link is provided in the returned result , Connect to others API Method , Make users not look up documents , And know what to do next
{
"status": 0,
"msg": "ok",
"results":[
{
"name":" KFC ( Luo Restaurant )",
"img": "https://image.baidu.com/kfc/001.png"
}
...
]
}
边栏推荐
- 总投资100亿美元,华虹无锡12吋晶圆厂正式投产
- The PRI that Hillhouse joined, including Junlian, Huakong, Shengshi, Lvdong and other 100 institutions, was killed
- Embedded sig | distributed soft bus
- 『MongoDB』你想要的MongoDB基本操作这里都有
- Unity operates on Explorer, opens explorer, selects files, and filters files
- Development status of Dao
- APP信息侦察&夜神模拟器Burp抓包配置
- 毕业5年,从信息管理转行软件测试工程师,我的月薪终于突破了12k
- LeetCode 122:买卖股票的最佳时机 II
- Embedded SIG | 分布式软总线
猜你喜欢

STM32 how to use serial port

Spend 120 billion to build a "subway" to connect 4 trillion cities. What is Guangdong thinking?

NVIDIA SMI error: NVIDIA SMI has failed because it could't communicate with the NVIDIA driver complete record

基于信心上界蒙特卡洛搜索树(UCT)实现四子棋

面试:你印象最深的BUG,举个例子

LeetCode 121:买卖股票的最佳时机
![[IO Development Notes] smart cloud intelligent watering device practice (3) - automatic code generation and transplantation](/img/f6/e23089c473cc72a7d763ff975d8e62.png)
[IO Development Notes] smart cloud intelligent watering device practice (3) - automatic code generation and transplantation

毕业5年,从信息管理转行软件测试工程师,我的月薪终于突破了12k

Monte Carlo search tree (UCT) based on confidence upper bound to realize four sub chess

leetcode:857. 雇佣 K 名工人的最低成本【分块思考 + 由简单入手】
随机推荐
Arduino实验一:双色灯实验
基于信心上界蒙特卡洛搜索树(UCT)实现四子棋
Summary of shell related commands
A chip company fell in round B
Spend 120 billion to build a "subway" to connect 4 trillion cities. What is Guangdong thinking?
证监会:同意传音控股科创板IPO注册
面试 必备
Five years after graduation, I changed from information management to software testing engineer, and my monthly salary finally exceeded 12K
Leetcode 122: the best time to buy and sell stocks II
what is qrc in qt
JSON字符串转化为JSON对象,获取某个key的值,判断某个key是否存在
2022-07-26:以下go语言代码输出什么?A:5;B:hello;C:编译错误;D:运行错误。 package main import ( “fmt“ )
让程序在一秒或者多秒中做一件事情
Use ECs and OSS to set up personal network disk
MySQL数据库介绍
CSRC: agree to the IPO registration of Chuanyin holding science and Technology Innovation Board
【论文阅读】LOGAN:Membership Inference Attacks Against Generative Models
Fujian vies for vc/pe
『MongoDB』你想要的MongoDB基本操作这里都有
Day07 MySql知识点再总结与多表查询