php - What to do about duplicate naming of routes in restful form?
黄舟
黄舟 2017-06-20 10:07:20
0
3
842

For example, this route
GET /users/{id}/comments
Now let’s say there is a message board on the user’s page, and we plan to use a comment component
For replies posted by users in some posts, use This is also the comment component
When designing the database, these two comment components use the same data table (polymorphic association) (you don’t have to worry about this)
The point is that this route has conflicting meanings:
Is it displaying the user message board (posted by others)?
Or is it displaying the user's replies in the post?

So, how to solve this problem and distinguish these two routes in the form of restful

Sorry, I am a Virgo,,,(but I also want to find the best solution to this problem)

Actually, there is another scenario for this problem, which is how to distinguish between those who follow me and those who follow me.
GET /users/{id}/follows
Does this route show those I follow or those who follow me?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(3)
为情所困

For your first scenario, I think there must be a field in the data table to identify whether the user's message board or post is in the user's message board. This field is temporarily called type, so it can be written as GET /users/ {id}/comments/{type}

In another scenario, you can use the parameter type to specify whether you are following me or following me. You can write GET /users/{id}/follows/{type}
Of course there is another way to follow me. of and those who follow me separately

GET /users/{id}/follows -> 我关注的
GET /users/{id}/followers -> 关注我的
学习ing

Leaving a message to a user and leaving a message to a post operate two different resources. Resources are located by URI. Different resources use different URIs. It is wrong for you to use the same URI to operate different resources.

给我你的怀抱

You can use message on the message board on the user page
followers are following me
following is what I am following
Just give me a few more English words.

I don’t think the questioner seems to have changed his name. In fact, the first reason for changing the name is that it can fundamentally solve the problem; the second reason is that it is convenient for subsequent maintainers. Using confusing names will cause problems sooner or later.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!