Simple REST URL scheme

一曲冷凌霜 提交于 2019-12-22 10:26:35

问题


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>

or would:

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

be a better way to go?


回答1:


You have three types of resources: Profiles, Journals, and Posts.

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.



来源:https://stackoverflow.com/questions/19033462/simple-rest-url-scheme

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!