DEV Community

Cover image for The Complete Guide to Status Codes for Meaningful ReST APIs - Let's start!

The Complete Guide to Status Codes for Meaningful ReST APIs - Let's start!

Lucas Santos on March 04, 2020

Photo by Joanna Kosinska on Unsplash For more than 10 years we've been working with HTTP and APIs following the ReST architecture. Most people thi...
Collapse
 
katnel20 profile image
Katie Nelson

Thanks for the great post Lucas.

I have A REST API with several POST endpoints that take in data, but return no data. Currently I’m returning status code 204 no content. Is that correct or should I just return 200 OK?

Collapse
 
_staticvoid profile image
Lucas Santos

It depends on what your POST requests do. For example, if your POST request is creating or updating something, then you should return 201 AND the created or updated resource, otherwise, if this is only something that will be processed later, you should return 202.

But, in the last case, if you're just doing an atomic transaction like "follow a user" or so, then 204 is just fine.

Collapse
 
katnel20 profile image
Katie Nelson

Hey Lucas, thanks for the reply. Most of the POSTS are for controlling a service (Start/Stop) kind of commands.

Thread Thread
 
_staticvoid profile image
Lucas Santos

Oh! In this case, my personal opinion is that you can use either 200 OR 204, I'd use 204 since it has no content to be returned, but if you do return something go for 200

Collapse
 
jeastham1993 profile image
James Eastham

Great write up Lucas, I was chatting about this just last night and thought to myself I wonder if I'm returning the write code. Now I know, so thankyou :-)

401/403 are ones that always catch me out

Collapse
 
_staticvoid profile image
Lucas Santos

Awesome! Thanks a lot for commenting! This is being a very fun article to write about :D

Collapse
 
mjamsek profile image
Miha Jamsek

It may be good to also write about status 204, as it is also used quite often.

Collapse
 
_staticvoid profile image
Lucas Santos

I wrote about it in the second part :D those we do not see too much but we should

Collapse
 
joaoparana profile image
João Antonio Ferreira

Very good series about HTTP Status Codes. Congratulations !

Collapse
 
rachelsoderberg profile image
Rachel Soderberg

The cats were very helpful with this lesson, thank you!

Collapse
 
diasalexandres profile image
Alexandre Dias

After discover "http status dogs" i became the inspector of status codes.

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

Status dogs have explanation. Status cats don't.

Collapse
 
dev_jessi profile image
Jéssica Félix

Que artigo perfeito!

Collapse
 
shefali_chopkar_87b9e3101 profile image
Shefali Chopkar

Loved this article, it helped me understand minor differences between status codes and when to use what