Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Status 200 with warnings?

What would you use for a successful HTTP status code but wanted to indicate some warnings? In my case, I'm making an ajax endpoint where you can add a new user. We expect a first and last name, but if there isn't one, the record will still be created and no followup to correct the situation will be expected. I just want the client to know "We created the record, and hey, BTW, the first and/or last name was blank"

I found this question, but that's about actual ensuing errors, not warnings.

like image 902
user151841 Avatar asked Sep 20 '13 21:09

user151841


2 Answers

It seems to be an optimal way to put something like {"status":"warn","meassage":"Name field is empty"} to the response body. There is no "warning" HTTP codes. You can of course use for example 201 CREATED for clean creation and 200 OK for warnings. But that's not a good way to use them.

like image 118
AlexZam Avatar answered Sep 27 '22 20:09

AlexZam


Don't use for this HTTP status.

Use for this body of response. For example in JSON

{warnings:true, warning:'We created the record, and hey, BTW, the first and/or last name was blank'}
like image 41
newman Avatar answered Sep 27 '22 18:09

newman