3

在我的网络应用程序中,我有一个user模型和一个journal模型post。每个用户可以有多个期刊,每个期刊可以有多个帖子。是否低于以 RESTful 方式表示这一点的最佳方式?

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

或者会:

/profiles/<username>
/journals/<journal_id>

是一个更好的方式去?

4

1 回答 1

0

您拥有三种类型的资源:个人资料、期刊和帖子。

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

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

如果您需要提供这些资源之间的逻辑映射和关系,您还需要提供以下内容:

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

您还可以查看此帖子,作为考虑资源之间业务关系映射的方法。

于 2013-09-26T17:24:51.583 回答