RESTful Web 服务的 URI - 第 2 部分

发布于 2024-09-28 10:22:55 字数 319 浏览 0 评论 0原文

我试图了解如何构建 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

百善笑为先 2024-10-05 10:22:55

只需考虑一下您的 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.

揽月 2024-10-05 10:22:55

看起来您正试图将方法链接滑入此处。如果您使用框架,您的方法可能最终看起来像这样:

 function profiles($pid=0,$likes=0,$which=0){} 

这可能更难以编程。

当你真正想要的时候:

 function listProfiles(){}
 function getProfile($profileID){}
 function getLikes($profileID){}
 function getLikeElement($profileID,$int){}

话虽这么说,你的实现完全取决于你。没有一个标准。

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:

 function profiles($pid=0,$likes=0,$which=0){} 

which can be more difficult to program.

when you may really be going for:

 function listProfiles(){}
 function getProfile($profileID){}
 function getLikes($profileID){}
 function getLikeElement($profileID,$int){}

This being said, your implementation is entirely up to you. There is no one standard.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文