假设我已经构建了一个用于做笔记的 REST 服务,如下所示:
GET /notes/ // gives me all notes
GET /notes/{id} // gives the note with the identified by {id}
POST /notes/ // creates note
PUT /notes/{id} // updates note identified by {id}
DELETE /notes/{id} // delete note
现在我想创建子资源,允许我获取/更新/删除第一个或最后一个注释。
GET /notes/first // get first note added
PUT /notes/last // updates last note added
DELETE /notes/first // delete first note
这是否违背了REST的原则?
先感谢您 :)
EDIT:
PS:在这个例子中我希望ID始终是一个数字
以我的拙见,这是完全合法且可取的。我特别喜欢的语义DELETE /notes/first
,但还要考虑POST /notes/first
- 将新注释放在第一个注释之前.
在你的情况下first
and last
是某种特殊的魔法标识符或占位符。另一方面,还有哪些替代方案?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)