Is it possible to have "extra" ID in the URL for REST API?

0 like 0 dislike
62 views
Hello! :)
API ranks.

Shops have users.
Need endpoint "update user" (change password, name, etc.). Which URL is more correct:
PATCH /users/:userId
OR
PATCH /shops/:shopId/users/:userId
Both URLs will work. Although the second URL is the extra id (shopId).
Error to have an extra ID in the URL?

Thanks in advance!
by | 62 views

2 Answers

0 like 0 dislike
Even if users are tied to the shops, once You admit the possibility of the use /users/:userId, assume user IDs are unique not only within the store, but the entire system. In this case, the level /shops/:shopId would be unnecessary in the task of changing information about the user even if the user has a reference to store in the plane's business logic. Therefore, use /users/:userId.
by
0 like 0 dislike
can.
but if the ID of the user enough to make changes and these changes are a definite better option 1. otherwise, it is better the second option.
example: change the user age and I must test does the shop have the user with the same age or not (content 18+). or when changing user needs some information about the shop is the same option 2 is better
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
0 comments
40,796 users