'I don't know how to decide path of API on REST API in updating user information situation

PATCH /api/users/:id/email => user update email
PATCH /api/users/:id/nickname => user update nickname

As above, I designed path of API based on Rest API.
but, I have a question
I am using jwt
jwt_token has id information of user
i think, better way is to use id of user in jwt_token instead of adding id of user to parameter.
but, I have a another question

PATCH /api/email => user update email
PATCH /api/nickname => user update nickname

if i use id of user in jwt_token, API path will change like a example above.
I think, it`s strange.
because, According to Rest API, use collection.(ex. users, books and so on..)
What is the right thing to do?
thank you for reading



Solution 1:[1]

"REST" is the architectural style on which the HTTP protocol was built. Every web page was intended to be "RESTful" and REST itself says nothing about what the API should look like. The query is obviously about modern APIs. A modern API MUST adhere to the RFCs and at the same time SHOULD adhere to common conventions. Common conventions make the REST API understandable to consumers. Further, I am answering with respect to modern APIs.


If you want to do partial update of resource, you should use PATCH method. There are two ways (RFCs) which you can use: RFC 6902 aka JSON Patch and RFC 7396 aka Merge Match. URL should target the updated resource (USER):

PATCH  /users/:id

BUT: You wrote that you want to update only authenticated user. In this case is common to use "special" URL:

PATCH /me/profile

You should send JSON body based on preferred RFC. In case if RFC 7396:

{
   "email": "[email protected]",
   "nickname": "newNickname"
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Miroslav Holec