2017-06-22 81 views
-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

回答

0

退房http://jsonapi.org/這爲構建JSON API的推薦規範。響應應包括數據和元數據

相關問題