简体   繁体   中英

What is the difference between 201 status code and 204 status code

在此处输入图像描述

what is the difference between 201 and 204

In practice, there isn't a lot of difference between a 200 with no content, a 201 and a 204: they all generically mean that the request succeeded:

  • a 200 response is the generic OK, and may or may not have a body attached;

  • a 201 response is for when the request specifically creates something and does not have a response body; and

  • a 204 response is for when the request succeeds but has no body to return.

200: OK Return an entity describing or containing the result of the action - when an object is created and returned (typically JSON for REST endpoint).

If all is OK, but there is no data to return the code is 204 No Content.

201: CREATED. The request has been fulfilled and resulted in a new resource being created. - when an object is created but only its reference is returned (such as an ID or a link)

Both 201 and 201 represent a successful request, For a more detailed explanation you can refer to the following documentation

201 Created

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.

204 No Content

The server has successfully fulfilled the request and that there is no additional content to send in the response payload body.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM