分页结果上的REST状态代码204 [英] REST status code 204 on paginated result
问题描述
我正在设计一个类似REST的API,用于基于YUI的客户端的分页数据检索. 对于GET请求,REST URL如下所示:
I am designing a REST like API for paginated data retrieval of a YUI-based client. The REST URL looks like this for a GET request:
/app/catalog/data?startIndex=<int>&results=<int>&sort=<sting>&dir=<string>
所有参数都是可选的,即,如果未提供任何参数,则将转储来自DB的所有数据. 现在说数据库中只有1000条记录.进行以下要求:
All parameters are optional, i.e. if no parameters are given, all data from DB will be dumped. Now say that there are only 1000 records in the database. Following reqeust is made:
/app/catalog/data?startIndex=1100&results=25
如果请求很好,但数据库的分页结果仍然为空,我应该返回什么状态代码?我无法确定这是204
还是404
.
What status code should I return if the paginated result from the database remains empty though the request was fine?! I can't decide whether this is 204
or 404
.
产生的媒体类型为JSON和CSV.
The produced media types are JSON and CSV.
推荐答案
我会说204最合适.请求成功,但没有结果.
I would say 204 is most appropriate. The request was successful, just with no results.
10.2.5 204 No Content
The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation.
听起来完全一样.
这篇关于分页结果上的REST状态代码204的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!