Reputation: 4122
In my app a user can change his password/name/etc by sending a PUT request to myapp.dev/user
When I send the request I have a authorization header for basic auth. So the backend will then find the user by checking the auth header.
But should I change my url to this instead: myapp.dev/user/user_id
When I check other API's I see that some include an id and some not, so what is the best practise?
Thanks
Upvotes: 0
Views: 121
Reputation: 1606
Definitely don't recommend adding the user_id if the context of the user_id is received elsewhere. Just adds extra burden and test cases.
I've seen either no id at all or "me" as a placeholder.
Upvotes: 0
Reputation: 2981
This will depend greatly on how you structure your app. In your case as the user is updating own profile. I strongly recommend dropping the id from the URI. Also it will save you the effort of identifying own user id, to send the correct endpoint.
Upvotes: 2