-1
我想确定什么最佳实践可能是为Restful API调用返回JSON响应。我读过多篇提供不同意见的博客和教程文章。我见过对Restful API调用的JSON响应的最佳做法?
一种方法提出任何宁静的调用返回同时包含元数据和结果数据的JSON响应,如下面所示的表示:
// response to a GET that returns an array of elements
{
"status": "success",
"count": 2,
"type": "LoadServingEntity",
"results":[ {
"lseId": 2756,
"name":"Georgia Power Co",
"code":"7140",
"websiteHome":"http://www.georgiapower.com/"
}, {
"lseId":1,
"name":"City of Augusta",
"code":"1000",
"websiteHome":null
}]
}
// an response that reports an API error
{
"status":"error",
"count":2,
"type":"Error",
"results":[{
"code":"NotNull",
"message":"An appKey must be supplied",
"objectName":"requestSignature",
"propertyName":"appKey"
}, {
"code":"NotNull",
"message":"An appId must be supplied",
"objectName":"requestSignature",
"propertyName":"appId"
}]
}
其他文章大便,大便这个方法。我即将开始一个新的API项目,我想从专家那里获得有关此主题最佳方法的反馈。
TIA