当前位置:网站首页>Restful API design specification
Restful API design specification
2022-07-06 08:29:00 【Liu Chu, Ge Nian】
PDF Download address :https://download.csdn.net/download/weixin_45525272/80429647
List of articles
- RESTful API design code
- ⼀、 What is? RESTful?
- Two 、 Design concepts and guidelines
- 3、 ... and 、 Why use RESTful API?
- Four 、 agreement
- 5、 ... and 、 domain name
- 6、 ... and 、 edition
- 7、 ... and 、http request ⽅ type
- 8、 ... and 、 route ( route )
- Nine 、 Filtering information (url in ? after ⾯ Parameters of )
- Ten 、 Status code
- 11、 ... and 、 Other
RESTful API design code
⼀、 What is? RESTful?
⼜ call REST(Representational State Transfer),⼀ Kind of Software architecture ⻛ grid 、 Design style , Not the standard , It just provides ⼀ Set design principles and constraints . It mainly ⽤ Software for client and server interaction .
Its core is ⾯ To resources ,REST Specifically for the network should ⽤ Design and development methods , To reduce the complexity of development , carry ⾼ Scalability of the system .
stay RESTful Architecture , Each website represents ⼀ Kind of resources (resource), So there can't be verbs in the website , Only nouns .
⼀ In general , The tables in the database are the same kind of records ” aggregate ”(collection), therefore API Nouns in should also make ⽤ The plural , Unless there is no proper plural form , Such as :weather.
Two 、 Design concepts and guidelines
- Everything on the network can be abstracted as resources (resource);
- Every resource has only ⼀ Resource ID for (resource identifier), Operations on resources do not change these identities ;
- All operations are stateless ;
- Layered system , Representation component ⽆ Can't understand the components outside the middle tier with which it interacts . By limiting system knowledge to a single layer , Can limit the complexity of the entire system , Promote the uniqueness of the bottom ⽴ sex .
3、 ... and 、 Why use RESTful API?
- Resources oriented (URI), Interpretive ;
- Behavior (GET / POST / PUT / PATCH / DELETE) And resources (URI) Separate , Lighter weight ;
- Data description is simple , send ⽤JSON、XML、PROTOBUFFER You can fully cover , Mainly make ⽤JSON;
Four 、 agreement
API And ⽤ User's communication protocol ,⼀ General envoy ⽤HTTP agreement , Make ⽤HTTPS.
5、 ... and 、 domain name
We should try our best to API Deployed in specialized ⽤ Under domain name :
https://api.example.com
If determined API It's simple , There will be no progress ⼀ Step expansion , Consider putting it under the primary domain name :
https://example.org/api/
6、 ... and 、 edition
At every API Corresponding URL in , due ⼀ Version number , In order to upgrade the service in the future , All versions of the client can be used normally , as follows :
https://api.example.com/v1/topics/
https://api.example.com/v2/topics/
https://api.example.com/v3/topics/
7、 ... and 、http request ⽅ type
| Request mode | meaning |
|---|---|
GET | Read (Read) |
POST | newly build (Create) |
PUT | to update (Update), Usually all updates |
PATCH | to update (Update), It's usually a partial update |
DELETE | Delete (Delete) |
8、 ... and 、 route ( route )
• Every ⽹ There must be no verbs in the address , Only nouns . And should make ⽤ The plural , except ⾮ There is no proper plural , Such as :weather.
https://api.example.com/v1/topics/ —> All posts ⼦
• For resources under individual or class names , You can directly add specific id To represent , as follows :
https://api.example.com/v1/topics/100001/info // id by 100001 My post ⼦ Details of
https://api.example.com/v1/users/12345/topics/ // id by 12345 Of ⽤ All posts under the account name ⼦
• More examples [ With request method ]
[GET] https://api.example.com/v1/topics/ — Get all posts ⼦( list )
[POST] https://api.example.com/v1/topics/ — New post ⼦
[PUT] https://api.example.com/v1/topics/100001 — Update the full post ⼦
[PATCH] https://api.example.com/v1/topics/100001 — Update post ⼦ Some information
[DELETE] https://api.example.com/v1/topics/100001 — Delete post ⼦
[GET] https://api.example.com/v1/groups/1/topics/ — Get all posts in a group ⼦( list )
[GET] https://api.example.com/v1/users/12345/profile — Get some ⽤ Household information
[PUT] https://api.example.com/v1/users/12345/profile — Update sth ⽤ Household information
[GET] https://api.example.com/v1/users/12345/labels — Get some ⽤ All labels
Nine 、 Filtering information (url in ? after ⾯ Parameters of )
Reasons for using filtered information :
single ⼀ Of url The path cannot represent all the scenes , Played a supplementary role ⽤;
?limit=10 : Specify the number of returned records ?offset=10 : Specify where to start the return record . ?page=2&per_page=100 : Designate the ⼏⻚, And every ⻚ Number of records . ?sortby=name&order=asc : Specifies which attribute to sort the returned results by , And sort order . ?animal_type_id=1 : Specify filter criteriaAvoid multiple levels URL, Not conducive to expansion , The meaning is not clear , It's difficult to understand ;
multistage URL:GET /authors/12/categories/2 // What does it mean ?The right thing to do is :
GET /authors/12?categories=2
Ten 、 Status code
HTTP The status code is ⼀ Three digits , Divided into five categories :
| Category | meaning |
|---|---|
| 1xx | Related information , Don't use |
| 2xx | Successful operation |
| 3xx | Redirect |
| 4xx | Client error |
| 5xx | Server error |
Unless it is 500 and 404 error ,⼤ Partially make ⽤ 200 Status code is enough , The returned data format is as follows :
11、 ... and 、 Other
(1)API Of ⾝ Certificates should use OAuth 2.0 frame .
(2) Data format returned by the server , Should be used as much as possible JSON, Avoid using XML.
边栏推荐
- matplotlib. Widgets are easy to use
- LDAP應用篇(4)Jenkins接入
- 面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
- 【MySQL】数据库的存储过程与存储函数通关教程(完整版)
- sys. argv
- 使用 BR 备份 TiDB 集群数据到兼容 S3 的存储
- [luatos-air551g] 6.2 repair: restart caused by line drawing
- China vanadium battery Market Research and future prospects report (2022 Edition)
- 从 SQL 文件迁移数据到 TiDB
- China high purity silver nitrate Market Research and investment strategy report (2022 Edition)
猜你喜欢

游戏解包的危害及资源加密的重要性

JS native implementation shuttle box

指针进阶---指针数组,数组指针

C language - bit segment
![[cloud native topic -45]:kubesphere cloud Governance - Introduction and overall architecture of enterprise container platform based on kubernetes](/img/ac/773ce8ee7f380df19edf8373250608.jpg)
[cloud native topic -45]:kubesphere cloud Governance - Introduction and overall architecture of enterprise container platform based on kubernetes

Résumé des diagrammes de description des broches de la série ESP
![[research materials] 2021 China online high growth white paper - Download attached](/img/51/bea6179e4fac88f8b550b4213a2bca.jpg)
[research materials] 2021 China online high growth white paper - Download attached

Online yaml to CSV tool

Wincc7.5 download and installation tutorial (win10 system)

被破解毁掉的国产游戏之光
随机推荐
Leetcode skimming (5.29) hash table
Migrate data from CSV files to tidb
CISP-PTE实操练习讲解
leetcode刷题 (5.28) 哈希表
China high purity silver nitrate Market Research and investment strategy report (2022 Edition)
Precise query of tree tree
面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
Vocabulary notes for postgraduate entrance examination (3)
Chrome浏览器的crash问题
What is the use of entering the critical point? How to realize STM32 single chip microcomputer?
【MySQL】数据库的存储过程与存储函数通关教程(完整版)
Colorlog结合logging打印有颜色的日志
C language - bit segment
Upgrade tidb operator
VMware virtualization cluster
Use Alibaba icon in uniapp
China dihydrolaurenol market forecast and investment strategy report (2022 Edition)
FairGuard游戏加固:游戏出海热潮下,游戏安全面临新挑战
Migrate data from a tidb cluster to another tidb cluster
Char to leading 0