开发者

Good URI design for logged in user specific resources

开发者 https://www.devze.com 2023-01-22 14:13 出处:网络
I wish to build up a website that follows the RESTful architecture. In my site, each user is identified by a permanent username and may manage their own settings. For the settings resource, I\'m torn

I wish to build up a website that follows the RESTful architecture. In my site, each user is identified by a permanent username and may manage their own settings. For the settings resource, I'm torn between two URI designs.

Option 1: /users/{username}/settings

Here is a generic settings resource URL pattern. Only the logged in user can do a GET/PUT to his/her specific settings resource. It's quite complicated though, as other user specific resources need to follow this lead. It makes admin authentications which have access to all the settings开发者_如何学Python of all users (or at least part of it) simpler.

Option 2: /my/settings

The URL for the settings resource of the currently logged in user. It's much simpler programming, but the URL doesn't really specify which resource it really is. The '/my' part becomes sort of an alias to '/users/{username}'.

Almost all websites follow a similar approach as option 2. What do you guys think?


Why not have both? Your /my could be just a redirect to /users/{myusername}/ This way, you can use /my in the UI, but your admin users can edit each users setting through the actual /users/{username} controller

0

精彩评论

暂无评论...
验证码 换一张
取 消