我正在實施一個web應用程序,並希望遵守RESTfull設計標準,我的問題是。集合類的REST風格的URL?
給定一個集合的類。
人{ ID ::整數 名:: string的 朋友::收藏者 的}
會是什麼 '最' 正確的方式來實現與人類的接口:
1.
example.com/REST/persons -> [... {id: '2', name: 'Pete', friends: [1,4,6]} ... ]
example.com/REST/persons/2 -> {id: '2', name: 'Pete', friends: [1,4,6]}
通過在人員類上使用某種搜索功能來查找朋友的位置?
或
2.
example.com/REST/persons -> [... {id: '2', name: 'Pete'} ... ]
example.com/REST/persons/2 -> {id: '2', name: 'Pete'}
example.com/REST/persons/2/friends -> [{id: '1', name: 'Joann'},
{id: '4', name: 'Jim'},
{id: '6', name: 'Charlie'}]
凡集合中的元素都擡頭看着我,在人的實例字段。
我已經看到兩件事情都實現了,但我想遵守standarts。
一條生路只是被我吞噬了。
example.com/REST/persons/2 -> {id : '2',
name : 'Pete',
friends: [example.com/REST/person/1,
example.com/REST/person/4,
example.com/REST/person/6]}
從而使得界面事件的更多問題的REST - 客戶端現在可以遍歷整個界面在不知道具體實現。
我希望有一些輸入在那裏。
你打算用什麼技術來實現你的REST API?這個選擇可以爲你做出這個決定。 –
此外,您的問題標題有誤導性,看起來您正在尋找網址格式,而不是實際的實施。 – Zepplock
@Zepplock:我改變了標題 –