分页结果上的 REST 状态代码 204 [英] REST status code 204 on paginated result

查看:19
本文介绍了分页结果上的 REST 状态代码 204的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个类似于 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.

听起来和情况完全一样.

Sounds exactly like the case.

这篇关于分页结果上的 REST 状态代码 204的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆