RESTful-基于SpringMVC实现优雅的API响应结构设计

一个规范、易懂和优雅,以及结构清晰且易于理解的API响应结构,完全可以省去许多无意义的沟通和文档。

预览

操作成功:

1
{"succeed": true,"timestamp": 1525582485337}

操作成功:返回数据

1
2
3
4
5
6
7
8
9
10
{
"succeed": true,
"result": {
"users": [
{"id": 1, "name": "name1"},
{"id": 2, "name": "name2"}
]
},
"timestamp": 1525582485337
}

操作失败:

1
2
3
4
5
6
7
8
9
{
"succeed": false,
"error": {
"error_code": 5002,
"error_reason": "illegal_argument_error",
"error_description": "The String argument[1] must have length; it must not be null or empty"
},
"timestamp": 1525582485337
}
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×