gpt4 book ai didi

rest - 对于已处理的 POST 请求,最合适的 HTTP 状态代码是什么?

转载 作者:行者123 更新时间:2023-12-04 16:29:47 24 4
gpt4 key购买 nike

我有一个 RESTful API,由另一个发布更新的内部应用程序使用。

问题是出现了一些意外的峰值,在这些时间内,请求可能需要超过 60 秒(负载均衡器定义的限制,我无法更改)来响应,这会导致 504 Gateway Timeout错误。

当后一个应用程序得到这样的响应时,它会在 10 分钟左右后再次重试请求。

这导致了一些请求被处理了两次,因为第一次请求成功了,但是耗时 60 多秒。

所以我决定使用 Idempotency Keys在避免此问题的请求中。问题是我不知道在这种情况下我应该返回什么。

我应该坚持使用 200 OK ?我应该退回一些 4xx代码?

最佳答案

我会说这在很大程度上取决于它是否对您来说是错误的。但我想说确切的响应代码更多的是品味问题而不是最佳实践。但是因为我猜你是在拒绝重复的请求,所以你想报告一个错误代码,比如 409 Conflict :

Indicates that the request could not be processed because of conflict in the current state of the resource, such as an edit conflict between multiple simultaneous updates.



https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_errors

Whenever a resource conflict would be caused by fulfilling the request. Duplicate entries and deleting root objects when cascade-delete is not supported are a couple of examples.



https://www.restapitutorial.com/httpstatuscodes.html

关于rest - 对于已处理的 POST 请求,最合适的 HTTP 状态代码是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51657018/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com