RESTful Web 服务的 URI - 第 2 部分
我试图了解如何构建 RESTful Web 服务的 URI。假设我有一个约会网站,以下内容是否正确:
- domain.com/profiles/ <-- 个人资料列表
- domain.com/profiles/123/ <-- 个人资料编号 123
- domain.com/profiles/123/likes / <-- 个人资料 123 的点赞列表
- domain.com/profiles/123/likes/2/ <-- 个人资料 123 的点赞列表中的第二项
我是接近还是完全错了?
I'm trying to understand how to construct URIs for RESTful web services. Assume I had a dating site, would the following be correct:
- domain.com/profiles/ <-- list of profiles
- domain.com/profiles/123/ <-- profile number 123
- domain.com/profiles/123/likes/ <-- list of profile 123's likes
- domain.com/profiles/123/likes/2/ <-- 2nd item in the list of profile 123's likes
Am I close or did I get this totally wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需考虑一下您的 URL 是否为 GET、POST、PUT 和 DELETE 请求提供有意义的操作。这就是 REST 的真正含义,而不是漂亮的 URL。
Just think about whether your URLs provide meaningful operations for GET, POST, PUT and DELETE requests. That's what REST is really about, rather than beautiful URLs.
看起来您正试图将方法链接滑入此处。如果您使用框架,您的方法可能最终看起来像这样:
这可能更难以编程。
当你真正想要的时候:
话虽这么说,你的实现完全取决于你。没有一个标准。
Looks like you are trying to slip method chaining into here. If you are using a framework, your method may end up looking like this:
which can be more difficult to program.
when you may really be going for:
This being said, your implementation is entirely up to you. There is no one standard.