As 0 is a boolean false and 1 a true, shouldn't APIs in HTTP return response_code 0 for Success instead of a 1?


3 Answers 3


There can be many reasons for an error and a parent process will often know what specifically went wrong with a child process. As such 0 is used for success and 1 to 255 provides flexibility for failure reason(s).

For example a child process could return:

  • 1 File not found
  • 2 User not authorized
  • 3 File locked by another process
  • 4 Connection not active
  • 5 Configuration incomplete
  • 6 Process cancelled by user

etc, etc.


Indicating errors as non-zero integers is in conformance with POSIX standard, aka conformance with Unix Standard, in particular with Error Numbers defined by library. This article, for instance, provides a good overview of the exit statuses. Therefore, whatever HTTP server processes we're discussing, they should strive to adhere to this standard if it expects to be portable across multiple systems, including Ubuntu, and yes - provide 0 on success. If we're talking about responses from an HTTP server ro a client, then API should conform to using HTTP status codes

  • 1
    I don't think HTTP status response codes should conform to the POSIX specification for function return or process exit status codes. HTTP status codes have their own entirely unrelated specification. May 27, 2018 at 9:30
  • 1
    @DavidFoerster Yes, agreed, those have their own specs. If we're talking about the actual software , as in server process that is running on the system, shouldn't that conform to POSIX specs, though ? Although, arguably, the question isn't clear as to which one it asks about, but I hope I clarified what I am talking about in my answer. May 27, 2018 at 9:38
  • 1
    Agreed but I still find your wording misleading. HTTP APIs are canonically programming interfaces used through HTTP connections and thus use HTTP status codes. If you're talking about HTTP server processes (whether they offer an HTTP API on their network sockets or not) and their status codes it would be better to not use the same term to avoid confusion. May 27, 2018 at 9:41

These numbers represents error, i.e. if there's is an error it is set to any positive number (1-255) and if there's no error it is set to 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.