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

标签 http http-status-codes

我有一个来自创建实体的 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/

相关文章:

python - InvalidSchema (“No connection adapters were found for '%s'”%url)

java - Java HttpClient 的响应流不正确

java - Jersey Web 服务发送 415 状态代码

ruby-on-rails - 使用 respond_with 服务 404?

validation - 返回 HTTP 409 是否适合验证检查?

c# - 使用C# HttpWebRequest 发送json数据到web服务

node.js - NodeJS HTTP GET 请求

json - 用于在 JSON 中上传文件的 REST API

error-handling - RestSharp GetAsync忽略响应错误状态码

rest - 在REST API中,分页资源: what would you return when a client request a page exceeding the maximum page number?