简单RESTURL方案

简单RESTURL方案,rest,restful-url,Rest,Restful Url,在我的web应用程序中,我有一个用户模型和一个杂志和post模型。每个用户可以有多个日志,每个日志可以有多篇文章。下面是以宁静的方式表达这一点的最佳方式吗 /profiles/<username> /profiles/<username>/journals/<journal_id> /profiles/<username>/journals/<journal_id>/posts/<post_id> /profiles/ /

在我的web应用程序中,我有一个
用户
模型和一个
杂志
post
模型。每个用户可以有多个日志,每个日志可以有多篇文章。下面是以宁静的方式表达这一点的最佳方式吗

/profiles/<username>
/profiles/<username>/journals/<journal_id>
/profiles/<username>/journals/<journal_id>/posts/<post_id>
/profiles/
/简介//期刊/
/简介//journals//posts/
或者会:

/profiles/<username>
/journals/<journal_id>
/profiles/
/期刊/

有更好的方法吗?

您有三种资源:简介、期刊和帖子

如果您的业务需要是允许最终用户访问所有资源,则需要根据您的需要对这些资源提供PUT/POST/GET/DELETE(您可能不需要对所有资源进行所有操作)

/profiles//
/期刊//
/职位//
如果需要提供这些资源之间的逻辑映射和关系,还需要提供以下内容:

/profiles/<username>/journals/<journal_id>
/profiles/<username>/journals/<journal_id>/posts/<post_id>
/profiles//journals/
/简介//journals//posts/

您还可以研究这一方法,了解资源之间的业务关系映射。

您可能会发现这一方法很有用。它有点旧,但仍然非常相关(官方rails指南也将其作为推荐资源)。感谢链接,刚刚读完。因此,一个扁平的层次结构被认为是经验法则,除非有其他因素需要考虑。我会设计它,所以用户必须为每个期刊选择URL段。URL中的数字id越少越好。一些系统甚至试图通过将post主题转换为一种临时URL slug来消除post_id。我不相信这不是过分的。@JC。谢谢,如果你提到它,肯定会在URL中使用大量的文章/杂志标题
/profiles/<username>/journals/<journal_id>
/profiles/<username>/journals/<journal_id>/posts/<post_id>