我用向量ids实现了Rest:
http://example.com/api/user/1
http://example.com/api/user/2
http://example.com/api/user/1,3
http://example.com/api/user/1,2,3Rest规定,如果"user/2“不存在,则返回404。
忽略可能涉及查询参数的解决方案,对于以下情况有哪些适当的响应?
用户/1,2-用户/1存在,用户/2存在
响应是一个200,两个元素都在一个集合中返回。
用户/1,3-用户/1存在,而user/3不存在
1?响应是200与用户1在一组?
2?响应是404,因为不能返回user/3?
既然我们有可能用1来处理空集?上面,这是否意味着
user/3 - user/3不存在
1?响应是200与一个空集?
发布于 2013-10-09 12:12:06
确保单个ID和多个ID(向量ID)的响应格式相同。这是REST原则之一: GET是一种“安全方法”(零幂等),应该不会产生副作用。
对于在GET请求中支持向量ID的端点,我通常使用类似于OpenSearch的响应格式。
在GET user/1,3中,用户/1存在且用户/3不存在,则返回带有
{
"startIndex": 0,
"count": 1,
"itemsPerPage": 1,
"entry": [
{ /* user/1 */}
]
}用户/3不存在的GET user/3返回200
{
"startIndex": 0,
"count": 0,
"itemsPerPage": 0,
"entry": []
}https://stackoverflow.com/questions/19187455
复制相似问题