restful 规范
接口
1.根据method不同,进行不同操作
GET/POST/PUT/DELETE/PATCH
2.面向资源编程
http://www.luffycity.com/salary
3.提现版本
建议用:
http://www.luffycity.com/v1/salary
http://www.luffycity.com/v2/salary
不建议用:
http://www.luffycity.com/v1/salary
http://www.luffycity.com/v2/salary
4. 体现是API
http://www.luffycity.com/api/v1/salary
http://www.luffycity.com/api/v2/salary
http://api.luffycity.com/v1/salary
http://api.luffycity.com/v2/salary
5.https
http://www.luffycity.com/api/v1/salary
http://www.luffycity.com/api/v2/salary
6.响应式设置状态码
200
300
400
500
return HttpResponse("adfasdf",status=300)
7.条件
https://www.luffy.com/apiv2/salary?page=1&size=10
8.返回值
https://www.luffy.com/api/v2/salary
GET:
[
{"id":1,"title":"高亮"},
{"id":2,"title":"龙泰"},
{"id":3,"title":"小东北"}
]
POST:返回新增的数据
{"id":1."title":"高亮"}
https://www.luffycity.com/api/v2/salary/1/
GET:获取单条数据
{"id":1."title":"高亮"}
PUT:更新
{"id":1."title":"高亮"}
PATCH:局部更新
{"id":1."title":"高亮"}
DELETE:删除
9.返回错误信息
{
code:100001,
error:"xxx错误"
}
10. Hypermedia API
ret={
code:1000,
data:{
id:1,
name:"小强",
depart__id:http://www.luffycity.com/api/v1/depart/8/
}
}