假设我们有一家在线商店,并收到更新某些订单的有效请求。
请求本身是有效的,但是假设订单有过期时间,并且已经过期,因此该请求实际上无法处理。
我怀疑这是否是一种验证错误。因为,正如我上面所说,请求本身是有效的;并且请求发送者可能不知道订单已经过期。
在这种情况下,REST API 服务返回的适当 HTTP 状态代码是什么?
警告:由于对产品的一般要求,应该是4XX
的一些错误代码!
UPD :更多信息:这个假定的“订单”仍然存在,甚至已经过期。可以取回它,但不能再操作它。这就是为什么代码 404
(例如)不合适。
最佳答案
我自己的版本:
我认为对于这种情况, 410
status code是最合适的:
The 410 response is primarily intended to assist the task of web
maintenance by notifying the recipient that the resource is
intentionally unavailable and that the server owners desire that
remote links to that resource be removed. Such an event is common
for limited-time, promotional services and for resources belonging to individuals no longer associated with the origin server's site. It
is not necessary to mark all permanently unavailable resources as
"gone" or to keep the mark for any length of time -- that is left to
the discretion of the server owner.
https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html :
The requested resource is no longer available at the server and no forwarding address is known. This condition is expected to be considered permanent. Clients with link editing capabilities SHOULD delete references to the Request-URI after user approval. If the server does not know, or has no facility to determine, whether or not the condition is permanent, the status code 404 (Not Found) SHOULD be used instead. This response is cacheable unless indicated otherwise
关于rest - REST API 服务为过期实体返回的适当 HTTP 状态代码是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49555743/