對於訂單管理應用程序,我需要設計適用於JSON的RESTful API。REST JSON API設計
我寧願我的API是這樣的,因此請求/響應包含JSON:
訂單查詢API
API: /orders/search
{
custname: "john",
orderdate: "10-jun-2013"
}
Response:
{
orders:[
{
orderid:234234,
orderstatus: NEW,
customer: "john"
}
]
}
訂購更新API
API: /orders/343455
Request Body:
{
orderstatus: "DELIVERED",
recepient: "joe"
}
Response:
{
status: ERROR,
message: "Order does not exist"
}
問題:
1.如何在GET請求中發送JSON(如在訂單搜索API中)。
2.我甚至想讓每個請求都是一個POST請求,並在主體中有JSON請求,提示操作是什麼 - 但是這仍然是REST(也許是'RESTful Web-Service'或'REST like Service') ?
3.我認爲它對我來說很重要,在大多數請求中發送JSON,這樣我的API實現不會發生太多變化,只是因爲我添加了刪除attribs到JSON消息。
4.有沒有任何其他人做過的例子,尤其是返回錯誤信息。
有什麼想法?