美文网首页
RESTful Service Best Practices:

RESTful Service Best Practices:

作者: BenjaminCool | 来源:发表于2018-12-11 17:25 被阅读0次

基本上,当前的最佳实践是使用以下属性包装常规(非JSONP)响应:

  1. code – contains the HTTP response status code as an integer.

  2. status – contains the text: “success”, “fail”, or “error”. Where “fail” is for HTTP status response values from 500-599, “error” is for statuses 400-499, and “success” is for everything else (e.g. 1XX, 2XX and 3XX responses).

  3. message – only used for “fail” and “error” statuses to contain the error message. For internationalization (i18n) purposes, this could contain a message number or code, either alone or contained within delimiters.

  1. data – that contains the response body. In the case of “error” or “fail” statuses, this contains the cause, or exception name.

A successful response in wrapped style looks similar to this:

{"code":200,"status":"success","data": {"lacksTOS":false,"invalidCredentials":false,"authToken":"4ee683baa2a3332c3c86026d"}}

An example error response in wrapped style looks like this:

{"code":401,"status":"error","message":"token is invalid","data":"UnauthorizedException"}

相关文章

网友评论

      本文标题:RESTful Service Best Practices:

      本文链接:https://www.haomeiwen.com/subject/neuehqtx.html