最好能遵守http协议,比如请求成功是200, 权限不够返回403根据http header里的status code 足够处理了状态码详细http://www.restapitutorial.com/httpstatuscodes.html 200成功,body就是需要的数据 有错误时,可以返回{error: "message"}就可以,没必要自己定义一系列code 关于状态码选择http://racksburg.com/choosing-an-http-status-code/
我觉得关于api这款返回code不需要那么多状态码了,常用的几个就好了,我常定义的结构如下 code:xxx,data:xxx,msg:xxxx code 我一般就两个 200 和 -1 ,200表示OK,-1 就是出错了 msg返回出错信息 data是数据区域,返回api接口数据
最好能遵守http协议,比如请求成功是200, 权限不够返回403
根据http header里的status code 足够处理了
状态码详细
http://www.restapitutorial.com/httpstatuscodes.html
200成功,body就是需要的数据
有错误时,可以返回{error: "message"}就可以,没必要自己定义一系列code
关于状态码选择
http://racksburg.com/choosing-an-http-status-code/