0

Is it good idea to use status codes not described in HTTP standard for REST responses of a REST API?

For example:

  • 470 or 770 - "User account not found"
  • 471 or 771 - "User account avatar not found"

What can be a problem except coincidence with a new status code of the standard?

Is there a codes range can be used for REST API special needs?

RoutesMaps.com
  • 1,628
  • 1
  • 14
  • 19
  • This is simply not expected usage of status codes. The idea behind HTTP and REST is that they're universal in their application. Doing custom things will "work" but the frameworks you work with on the front or back end might make your life hell for it, and if you have any hopes of other devs working on or with your API, they will not have an easy time. Better is sending the standard status codes with a custom message in the body. 404: account / avatar not found... standard for a resource that can't be found. or possibly 401: Unauthorized may be appropriate for the case of a login – bryan60 Dec 20 '18 at 19:34
  • Possible dup of https://stackoverflow.com/questions/7996569/can-we-create-custom-http-status-codes – Salman A Dec 20 '18 at 19:49
  • If you do read that question, please listen to Julian Reschke, who literally wrote the HTTP spec. – Eric Stein Dec 20 '18 at 21:14
  • It's double-plus-ungood, bordering on thoughtcrime. – EJoshuaS - Stand with Ukraine Dec 20 '18 at 23:20

1 Answers1

0

The HTTP standard provides status codes to describe the return values. It is hard to work to the client with an API that ignores the standard HTTP status. So, the server should always return the right status code.