REST API框架。推荐行为无效的查询参数 [英] REST API Framework. Recommended behavior for invalid querystring parameter

查看:145
本文介绍了REST API框架。推荐行为无效的查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现一个REST API框架,我不知道该recommendedbehavior是什么,当一个客户端提交了无效的查询参数。

I am implementing a REST API Framework, and I wonder what the recommendedbehavior is, when a client submits an invalid querystring parameter.

我要说明我的意思用一个具体的例子:
我说,我对/ API /联系人/端点的API处理程序,并处理程序提供了一个名为 ID 查询字符串过滤器,使客户能够选择与所提供的ID一定的接触

I will illustrate what I mean with a specific example: Say, I have an API handler on the /api/contacts/ endpoint, and the handler provides a querystring filter named id, which enables clients to select certain contacts with the provided IDs.

所以,GET或DELETE请求可能是 / API /联系人/ ID = 2及?ID = 4和; n = lalalala

So, a GET or DELETE request could be /api/contacts/?id=2&id=4&id=lalalala.

显然,有没有这样的东西用 ID的联系= lalalala 。在这种情况下,应该在服务器表现怎么样?

Clearly, there is no such thing as a Contact with id=lalalala. In this case, what should the server behave like?


  • 忽略与 ID无效联系= lalalala ,只筛选的有效身份证件,2和触点4。

  • Ignore the invalid Contact with id=lalalala, and only filter the contacts on the valid ids, 2 and 4.

有错误code,表示这个错误响应。如果是的话,应提供哪些错误code?

Respond with an error code that indicates this error. If yes, which error code should be provided?

先谢谢了。

编辑:澄清;该框架的主要焦点我开发的,是有一个predictable行为,因此响应codeS。出于这个原因,我想客户消费建立在这个框架的一个API,以期望尽可能少的惊喜。
因此,问题基本上是:应在API在这种情况下返回一个错误(以及如果是,它)?或忽略无效的过滤条目,只有在正确的查询字符串参数过滤?

To clarify; The main focus of the framework I develop, is having a predictable behavior and hence response codes. For this reason, I want the clients consuming an API built on this framework, to expect the least possible surprises. So, the question basically is: Should the API return an error in this case(and if yes, which)? Or ignore invalid filter entries, and only filter on the correct querystring parameters?

推荐答案

继法律条文,响应应该是404未找​​到。然而,没有人会与你取得太难过,如果你preFER返回400 - 错误的请求

Following the letter of the law, the response should be a 404 Not found. However, nobody is going to get too upset with you if you prefer to return 400 - bad request.

我肯定会虽然返回4xx状态code。你想客户知道,他们犯了一个错误。

I would definitely return a 4XX status code though. You want the client to know that they made an error.

这篇关于REST API框架。推荐行为无效的查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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