HTTP

HTTP 201 Created vs 204 No Content

Both HTTP 201 (Created) and 204 (No Content) belong to the 2xx Success category. 201 indicates that the request succeeded and a new resource was created. Typically returned after POST or PUT requests that create a new entity. Meanwhile, 204 means that the server successfully processed the request but is not returning any content. Common for DELETE operations and form submissions that don't need a response body.

Deskripsi

The request succeeded and a new resource was created. Typically returned after POST or PUT requests that create a new entity.

Ketika Anda Melihatnya

After successfully creating a new user, post, order, or other resource via a REST API.

Cara Memperbaiki

No fix needed. Check the Location header for the URL of the new resource.

Deskripsi

The server successfully processed the request but is not returning any content. Common for DELETE operations and form submissions that don't need a response body.

Ketika Anda Melihatnya

After DELETE requests, PUT updates where no body is needed, or CORS preflight responses.

Cara Memperbaiki

No fix needed. The action was successful; there is simply no content to return.

Perbedaan Utama

1.

HTTP 201: The request succeeded and a new resource was created. Typically returned after POST or PUT requests that create a new entity.

2.

HTTP 204: The server successfully processed the request but is not returning any content. Common for DELETE operations and form submissions that don't need a response body.

3.

You encounter 201 when after successfully creating a new user, post, order, or other resource via a REST API.

4.

You encounter 204 when after DELETE requests, PUT updates where no body is needed, or CORS preflight responses.

Kapan Menggunakan Yang Mana

For 201 (Created): No fix needed. Check the Location header for the URL of the new resource. For 204 (No Content): No fix needed. The action was successful; there is simply no content to return.

Pelajari Lebih Lanjut