开发者

Custom http codes

Could I use custom HTTP codes?

I want to use these codes as response for AJAX requests.

Example:

220 - will be correspond to status that some item was created successfully 420 - will be correspond to status that some validations errors were occurred

Each r开发者_JS百科esponse will be has json string.


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

If this is just between your server and your client, simply put the additional information into the response body and use a more generic status code.

That being said -- what you called "420" is already defined as "422 Unprocessable Entity".


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜