Custom http codes

Can I use custom HTTP codes?

I want to use these codes as an answer to AJAX requests.

Example:

220 - will correspond to the status that some element was created successfully 420 - will correspond to the status that some verification errors have occurred

Each response will contain a json string.

+4
source share
2 answers

You can define extension codes, but that makes sense if you want to standardize something; in this case you need to write a specification and get a registered status code (see http://greenbytes.de/tech/webdav/draft-ietf-httpbis-p2-semantics-12.html#rfc.section.4.1 ).

If it is only between your server and your client, simply add additional information to the response body and use a more general status code.

The aforesaid - what you called "420" is already defined as "422 Unprocessable Entity".

+2
source

Using your server-side language of choice, you can send headers to the browser with the appropriate HTTP code and message.

0
source

Source: https://habr.com/ru/post/1340618/


All Articles