Reputation: 4411
I'm writing an API in Django Rest Framework.
I have a password reset endpoint that accepts one 'email' parameter. What if there is a key 'email' in the header, but the value was an empty string?
key: 'email'
value: ''
What status code should I return? 400, or maybe 204?
EDIT: I forgot to mention that this shouldn't be a validation failure. No authorization is needed for this endpoint. This is only serves to send a password reset email.
Upvotes: 1
Views: 4833
Reputation: 2457
Http statuses are just standards, you can adjust them to suit you. 204 no content is generally used when no response body is returned, so you want be able to respond from server with "no email provided whatever error massege". In DRF, 204 is returned (as default) after successful DELETE request, when entity was deleted at server, so there is no content left.
In your case I would go with 400. http://www.restapitutorial.com/httpstatuscodes.html is specifically mentioning "missing data" as an example of error 400 bad request usage, which might be exactly your case.
Upvotes: 5