Is using magic (me/self) resource identifiers going against REST principles?

前端 未结 3 1362
独厮守ぢ
独厮守ぢ 2020-12-08 11:19

I\'ve seen URIs that support magic ids for the authenticated user like below:

GET /user/me - list my profile
GET /user/me/photos - list my photos
         


        
3条回答
  •  时光说笑
    2020-12-08 11:32

    That is perfectly fine.

    Whether it is the same entity in the database is irrelevant, the more correct description would be that every concept needs to have a URI. The concept of "current user" is different from "user 742924", so it is ok.

    It can be even worse than that, "current user", "last logged in user", "user with name starting with A", "oldest user", etc. All of those can be different resources, even though they may point to the same "user".

提交回复
热议问题