Welcome tag moderator AKA Unofficial DEV cheerleader. While most of my friends are found on SnapChat or Tic-Toc, you can find me here. And I OOP, but I’m not a VSCO girl.
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?
Brazilian developer since 2011. Microsoft MVP, Docker Captain, and Google Dev Expert. OpenJS foundation member and Node.js contributor. Loves JavaScript and TypeScript.
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.
Welcome tag moderator AKA Unofficial DEV cheerleader. While most of my friends are found on SnapChat or Tic-Toc, you can find me here. And I OOP, but I’m not a VSCO girl.
Brazilian developer since 2011. Microsoft MVP, Docker Captain, and Google Dev Expert. OpenJS foundation member and Node.js contributor. Loves JavaScript and TypeScript.
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
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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?
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.
Hey Lucas, thanks for the reply. Most of the POSTS are for controlling a service (Start/Stop) kind of commands.
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