A
A
alpha-kappa2017-08-04 19:21:04
API
alpha-kappa, 2017-08-04 19:21:04

What HTTP status to give to the client?

There is a nodejs-server with a chat where users communicate.
There is a separate php-server that can send messages to specific users in this chat.
To do this, it sends a POST request to the nodejs server indicating to whom (user_id) and what (message body) to send.
Next , the chat server looks for a user with the required user_id and sends him the received message.
After a successful send, it responds to the php server with the 200th status indicating that the message has been sent to the addressee.
The question is what status code to respond to the php server if the chat server has not found a user with this user_id.
404(Not Found) - not good - we got through to the resource.
500 (Internal Server Error) - also not - the server is not broken
200 (Ok) - well, what's the "ok" if the message was not sent to the addressee.
note For now, I'm leaning towards the usual 200, but in the body, pass my status: "success" or "error" with a message explaining the reason for the error. Well, on the php side , parse the response body and decide what to do next.
Answer: You will have to use the option from the note above. The rest of the options are not convincing.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2017-08-04
@alpha-kappa

So far I'm leaning towards the usual 200, but in the body I send my status: "success" or "error" with a message explaining the reason for the error. Well, on the php side, parse the response body and decide what to do next.
Many api developers (myself included) do just that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question