DEV Community

loading...

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

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
khaosdoctor profile image
Lucas Santos Author

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
khaosdoctor profile image
Lucas Santos Author

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