Search code examples
apirestserverresponse

what is appropriate response status code from server when there is no empty space for user in chat room?


I'm building a chat app using node.js koa. the basic rule of chatting room has limit numbers of user joining,(It's PUT request) I'm struggling upon give appropriate response status code to client side.

I already checked some documents, here is some candidates I found.

400 bad request 422 Unprocessable entity 403 forbidden

In 400 bad request actually it's not a bad request from client. client abide by rules between client-server. When it comes to 422 Unprocessable entity it looks more sense when data is not exist in database, which is not my case.

If you are familiar with building rest api, I ask you give me some advice.


Solution

  • Status codes are meta data in the transfer of documents over a network domain. They are used to allow general purpose components to correctly interpret, and act upon, the response message.

    Which is to say, you need to be thinking about what's going on at the document level, not what things mean in your specialized domain ("HTTP is an application protocol, but it's not your application protocol" -- Webber, 2011).

    403 Forbidden is fine.

    409 Conflict is also fine.

    422 Unprocessible Entity isn't quite right, based on your description. 422 is "That doesn't mean anything to me", not "I can't do that right now".

    The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions. For example, this error condition may occur if an XML request body contains well-formed (i.e., syntactically correct), but semantically erroneous, XML instructions.