Short answer
You can use me in the url to refer to the current user. With this approach, you will have a URL like this: /users/me/books .
Answer to every question
userId provide URL redundancy? When we receive a token with each call, we can find out which user is making the call and returning his list of books. userId is not strictly required.
You can do the following: /users/me/books . Where me refers to the current user. This is easier to understand than /users/books , which can be used to return all books from users.
For some flexibility, besides /users/me/books , you can support /users/{userId}/books .
The URL /users/me can be used to return data from the current user. Many APIs such as StackExchange , Facebook , Spotify, and Google+ take this approach.
Would remove the userId break REST tags because /users/books/ looks like it should return all books for all users?
I do not think that this violates any REST principles, but I think that your resources will not be properly allocated. As I said above, I would use /users/me/books , as well as support for /users/{userId}/books .
Should I just bite the bullet and check it for a token, and then check that the token belongs to the same userId ?
When using the userId in the URL to request personal information from the user, there is no harm in checking whether the token belongs to the user with the userId included in the URL.
source share