要在深度分页限制后使用哪个状态代码

huangapple go评论53阅读模式
英文:

Which status code to use after deep pagination limit

问题

我们有一个API,我们希望拒绝超过第99页的请求。

EG:

GET example.com/users?page[number]=99 # 允许,返回200 OK
GET example.com/users?page[number]=100 # 不允许,返回???

最适合返回的状态代码是什么?

我们考虑:

  • 400:太一般了
  • 403:最有可能
  • 410:已删除。也许,但旧方法不是临时的
  • 422:接近,但包括:“服务器无法处理包含的指令”,不太准确
  • 429:不遵守Retry-After
英文:

We have an API and we want to reject requests beyond page 99.

EG:

GET example.com/users?page[number]=99 # Allowed, returns 200 OK
GET example.com/users?page[number]=100 # Disallowed, returns ???

What is the most appropriate status code to return?

We are considering:

  • 400: Too generic
  • 403: Most likely
  • 410: Gone. Maybe, but the old way was not temporary
  • 422: Close, but includes: "the server was unable to process the contained instructions", not quite accurate
  • 429: Doesn't honour Retry-After

答案1

得分: 1

400-Bad Request: 请求似乎合适。您可以在响应正文中包含错误详细信息,例如解释为何这是一个错误请求(例如页面限制)。

403-Forbidden: 似乎不太合适,这不是一个访问问题。

422-Unprocessable Content: 也许这个可以工作,一旦请求语法正确。

429-Too Many Requests: 不是这种情况。

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses

英文:

400-Bad Request: Looks appropriate.
You can include error details in the response body, like a message explaining why it is a bad request (page limit)

403-Forbidden: It does not look to fit well, it is not an access matter.

422-Unprocessable Content: Maybe this one works, once the request syntax is correct.

429-Too Many Requests: It is not the case.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses

huangapple
  • 本文由 发表于 2023年3月1日 09:11:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75598755.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定