创建但 returns 没有数据的端点的状态代码
Status Code for an endpoint that creates but returns no data
我有一个来自创建实体的 REST API 的端点,但端点没有 return 任何数据。
return 一个 201
状态码可以吗?或者 return 一个 204
状态码会更好?
哪一个赢了?
201
状态码表示资源已创建。 204
状态码不适合这种情况。
创建资源请求的响应应具有 201
状态代码和 Location
HTTP header 以及标识新创建实体的 URI。引用 RFC 7231,HTTP/1.1 协议的语义和内容的当前参考:
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. [...]
我有一个来自创建实体的 REST API 的端点,但端点没有 return 任何数据。
return 一个 201
状态码可以吗?或者 return 一个 204
状态码会更好?
哪一个赢了?
201
状态码表示资源已创建。 204
状态码不适合这种情况。
创建资源请求的响应应具有 201
状态代码和 Location
HTTP header 以及标识新创建实体的 URI。引用 RFC 7231,HTTP/1.1 协议的语义和内容的当前参考:
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 aLocation
header field in the response or, if noLocation
field is received, by the effective request URI. [...]