赞
踩
######说明:适用于Web前后端分离
参考链接:RESTful API 最佳实践
GET
,POST
以外的请求:
GET
:读取请求,如列表,详情接口POST
:创建请求,如新增一条数据PUT
:更新(Update),通常更新整个实体PATCH
:部分更新DELETE
:删除GET /users
:读取用户列表GET /users?page=1&size=10
:分页读取用户列表(第1页,每页10条数据)GET /users/1
:读取id为1的用户详情GET /users?source=wechat
:读取来自微信的用户POST /users
: 创建用户PATCH /users/1
:更新id为1的用户信息DELETE /users/1
:删除id为1的用户信息GET /users/1/followers
:读取id为1的用户的粉丝列表GET
:200,成功POST
:201,创建成功PUT
:200,成功PATCH
:200,成功DELETE
:200,已删除301
:永久重定向,浏览器直接跳转302
、307
:暂时重定向,浏览器直接跳转303
:暂时重定向,指定跳转URL,前端询问用户是否跳转,如 HTTP/1.1 303 See Other
Location: /users/1
400 Bad Request
:无效请求,服务器不理解前端请求401 Unauthorized
:用户没有提供身份凭证凭据或没有通过身份验证(如未登录,登录信息失效)403 Forbidden
:用户通过了验证,但是不具有访问资源所需的权限(功能权限或数据权限)404 Not Found
:请求资源不存在或不可用(如已删除资源)405 Method Not Allowed
:用户已通过验证,但是所用的HTTP方法不符合要求(如GET方法使用POST请求)410 Gone
:资源已从该地址转移,不再可用(如文件转移)415 Unsupported Media Type
:客户端要求的返回格式不支持,如只能返回JSON格式,客户端要求返回XML格式。422 Unprocessed Entity
:客户端上传的实体无法处理(如数据不完整,数据校验不通过),导致请求失败。429 Too Many Requests
:客户端请求的次数超过限额。500 Internal Server Error
:客户端请求有效,服务器处理出现异常(如SQL执行错误,程序执行异常)503 Service Unavailable
:服务器无法处理请求,通常用于网站维护状态JWT
做鉴权,JWT
的访问令牌token
通过HTTP Header
返回对于返回HttpStatus为2XX ,表示示例数据如下:
{
"pageSize": 2,
"pageNum": 1,
"total": 6,
"list": [
{
"id": 7,
"deptName": "xxx部门",
"deptCode": "001",
"sort": 1,
"createOn": null,
"createBy": "ut ullamco nulla",
"modifyOn": null,
"modifyBy": "culpa",
"delFlag": 1,
"parentId": 1,
"enterpriseCode": "1",
"qywxDeptId": "002",
"qywxStatus": 1,
"jdId": null,
"jdParentId": null,
"deptPhone": null,
"deptFax": null,
"deptAddress": null
},
{
"id": 6,
"deptName": "我房旅居",
"deptCode": "001",
"sort": 1,
"createOn": null,
"createBy": "ut ullamco nulla",
"modifyOn": null,
"modifyBy": "culpa",
"delFlag": 1,
"parentId": 1,
"enterpriseCode": "1",
"qywxDeptId": "002",
"qywxStatus": 1,
"jdId": null,
"jdParentId": null,
"deptPhone": null,
"deptFax": null,
"deptAddress": null
}
]
}
[
{
"id": 7,
"deptName": "xxx部门",
"deptCode": "001",
"sort": 1,
"createOn": null,
"createBy": "ut ullamco nulla",
"modifyOn": null,
"modifyBy": "culpa",
"delFlag": 1,
"parentId": 1,
"enterpriseCode": "1",
"qywxDeptId": "002",
"qywxStatus": 1,
"jdId": null,
"jdParentId": null,
"deptPhone": null,
"deptFax": null,
"deptAddress": null
},
{
"id": 6,
"deptName": "我房旅居",
"deptCode": "001",
"sort": 1,
"createOn": null,
"createBy": "ut ullamco nulla",
"modifyOn": null,
"modifyBy": "culpa",
"delFlag": 1,
"parentId": 1,
"enterpriseCode": "1",
"qywxDeptId": "002",
"qywxStatus": 1,
"jdId": null,
"jdParentId": null,
"deptPhone": null,
"deptFax": null,
"deptAddress": null
}
]
{
"id": 1,
"deptName": "xxx集团",
"deptCode": "dfsadf",
"sort": null,
"createOn": "2019-04-16T01:02:29.000+0000",
"createBy": null,
"modifyOn": "2019-04-16T01:02:29.000+0000",
"modifyBy": null,
"delFlag": 0,
"parentId": null,
"enterpriseCode": "1",
"qywxDeptId": null,
"qywxStatus": null,
"jdId": null,
"jdParentId": null,
"deptPhone": null,
"deptFax": null,
"deptAddress": null
}
对于返回HttpStatus为3XX、4XX、5XX ,表示示例数据如下:
//对于错误提示信息,规则如下:前端先获取二级错误信息data信息展示,如二级错误信息为null,则展示一级错误msg信息
{
data: "密码不少于6位",
code: 2004,
msg: "Password does not comply with regulations "
sys:"naliwan"
}
//多条错误明细
{
data: [{"message":"密码不少于6位"},{"message":"密码必须包含数字和字母"}],
code: 2004,
msg: "Password does not comply with regulations "
sys:"naliwan"
}
名称 | 参数名 | 数据类型 | 备注 |
---|---|---|---|
业务错误码 | code | int | 各个系统错误业务码 |
错误信息 | msg | String | 自定义错误信息,如:密码不符合规定 |
错误系统码 | sys | String | 如:xxx系统报错naliwan |
错误详细信息 | data | String | 如:密码不少于6位 |
2004
2 | 004 |
---|---|
服务级错误(1为系统级错误) | 具体错误代码 |
错误代码 | 错误信息 | 详细描述 |
---|---|---|
1001 | System error | 系统错误 |
1002 | Service unavailable | 服务暂停 |
1003 | Remote service error | 远程服务错误 |
1004 | IP limit | IP限制不能请求该资源 |
1005 | Unsupport mediatype | 不支持的MediaType |
1006 | Param error, see doc for more info | 参数错误 |
1007 | Unsupport mediatype | IP限制不能请求该资源 |
1008 | Too many pending tasks, system is busy | 任务过多,系统繁忙 |
1009 | Job expired | 任务超时 |
1010 | RPC error | RPC错误 |
1011 | Illegal request | 非法请求 |
1012 | Invalid user | 应用的接口访问权限受限 |
1013 | Insufficient app permissions | RPC错误 |
1014 | Miss required parameter (%s) , see doc for more info | 缺失必选参数 (%s) |
1015 | Parameter (%s)'s value invalid, expect (%s) , but get (%s) , see doc for more info | 参数值非法,需为 (%s),实际为 (%s) |
1016 | Request body length over limit | 请求长度超过限制 |
1017 | Request api not found | 接口不存在 |
1018 | HTTP method is not suported for this request | 请求的HTTP METHOD不支持 |
1019 | IP requests out of rate limit | IP请求频次超过上限 |
1020 | User requests out of rate limit | 用户请求频次超过上限 |
1021 | User requests for (%s) out of rate limit | 用户请求特殊接口 (%s) 频次超过上限 |
1022 | The record already exists in the database | 数据库中已存在该记录 |
1023 | The path does not exist. Please check if the path is correct | 路径不存在,请检查路径是否正确 |
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。