7
7
700ghz2019-01-30 08:10:44
RESTful API
700ghz, 2019-01-30 08:10:44

Is it possible to have an "extra" ID in a REST API URL?

Hello! :)
Building an API.
Stores 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 has an extra id (shopId).
Is it wrong to have an extra ID in the URL?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
luna3956, 2019-01-30
@700ghz

Even if users are tied to stores, then since you allow the use of /users/:userId, I assume that user IDs are unique not only within the store, but throughout the entire system. In this case, the level /shops/:shopIdwill be redundant in the task of changing user information, even if the user has a link to the store in the business logic plane. Therefore, use /users/:userId.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question