简单的 REST URL 方案 [英] Simple REST URL scheme
问题描述
在我的网络应用程序中,我有一个 user
模型和一个 journal
和 post
模型.每个用户可以有多个期刊,每个期刊可以有多个帖子.下面是以 RESTful 方式表示这一点的最佳方式吗?
In my web app I've got a user
model and a journal
and post
model. Each user can have multiple journals, each journal can have multiple posts. Is below the best way to represent this in a RESTful way?
/profiles/<username>
/profiles/<username>/journals/<journal_id>
/profiles/<username>/journals/<journal_id>/posts/<post_id>
或者会:
/profiles/<username>
/journals/<journal_id>
有更好的方法吗?
推荐答案
您拥有三种类型的资源:个人资料、期刊和帖子.
You have three types of resources: Profiles, Journals, and Posts.
如果您的业务需要允许最终用户访问它们,您需要提供 PUT/POST/GET/DELETE CRUD 操作基于您的需要(您可能不需要对所有资源进行所有操作)
If your business needs is to allow end-users to have access to them all, you will need to provide PUT/POST/GET/DELETE CRUD operations on these resources base on your needs (you may not need all operations on all resources thought)
/profiles/<username>/
/journals/<journal_id>/
/posts/<post_id>/
如果您需要提供这些资源之间的逻辑映射和关系,您还需要提供以下内容:
If you need to provide a logical mapping and relationship between these resources, you will also need to provide the following:
/profiles/<username>/journals/<journal_id>
/profiles/<username>/journals/<journal_id>/posts/<post_id>
您还可以查看此发布为什么可能是思考资源之间业务关系映射的方法.
You can also look into this posting as what may be the approach to think about business relationship mapping between resources.
这篇关于简单的 REST URL 方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!