gpt4 book ai didi

http - 创建但不返回数据的端点的状态代码

转载 作者:可可西里 更新时间:2023-11-01 17:29:21 26 4
gpt4 key购买 nike

我有一个来自创建实体的 REST API 的端点,但该端点不返回任何数据。

返回 201 状态码可以吗?或者返回一个 204 状态码会更好?

谁赢了?

最佳答案

201 状态码表示资源已创建。 204 状态码不适合这种情况。

对创建资源的请求的响应应具有 201 状态代码和 Location HTTP header 以及标识新创建实体的 URI。引用 RFC 7231 , HTTP/1.1 协议(protocol)的语义和内容的当前引用:

6.3.2. 201 Created

The 201 (Created) status code indicates that the request has been fulfilled and has resulted in one or more new resources being created. The primary resource created by the request is identified by either a Location header field in the response or, if no Location field is received, by the effective request URI. [...]

关于http - 创建但不返回数据的端点的状态代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40050779/

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