我們目前正在設計一個內部REST api。我們有以下的用例:REST API設計 - 查詢郵件數據 - 選擇哪種毒藥?
- 用戶(109)想讀的消息,他派給其他用戶(110)
- 閱讀用戶(109)通過他的令牌已知應用憑據,他驗證之後收到的(同時做GET請求)
- 我們在這個例子中假設用戶109是發送者和110的接收器
從用戶的角度總結「給我的郵件,我(109)已發送到110「
名以下的URI來我們的腦海中,但我們不能決定採取哪一種:
a) GET http://localhost:9099/api/mails/109?receiverUserId=110
b) GET http://localhost:9099/api/mails?senderUserId=109&receiverUserId=110
c) GET http://localhost:9099/api/mails?receiverUserId=110
d) GET http://localhost:9099/api/mails/me/to/110 (when logged in as 109 via token credentials we know that "me" is 109)
f) GET http://localhost:9099/api/mails/109/to/110 (explicit request, e.g. for admins … has to be guarded against illegal access)
所有環節都「上下文敏感」正在發送一個鏈接到接收器(110)將會產生執行GET請求的不同結果。
我想知道您對使用哪個網址的看法。
任何幫助高度讚賞。
歡呼 燙髮
只是一個觀察:(b)和(d)是相同的。 – ArjunShankar 2012-04-13 09:04:16
啊對不起,你說得對;-) – Marcel 2012-04-13 12:16:45
我投給c。衆所周知,我沒有看到指出閱讀用戶的觀點。 (雖然緩存除外) – njzk2 2012-04-13 12:22:06