Spring REST URI: How to differentiate b/w user and admin

时间:2017-03-16 23:22:12

标签: java spring rest spring-rest

I am a bit confused and need help in understanding the way I can define my REST URI for users.

Requirement: I wanted to achieve something like below:

  1. GET URI: /users/me/addresses: This API will be invoked by client only(iOS). The user detail will be fetched from auth token and the returned object will exclude some of the fields.
  2. GET URI: /users/{userId}/addresses: This API will be invoked by customer care WEB portal and the returned object will have all the fields

To achieve this I exposed two methods one with URI '/users/me/addresses' and other with '/users/{userId}/addresses'. However seems Spring consider both of the API as same and doesn't allow that. So I am looking for an alternative approach to achieve my goal.

1 个答案:

答案 0 :(得分:0)

你可以使用regexp使spring认为两个映射是不同的。请参阅the documentation

@RequestMapping("/users/{userId:\\d+}/addresses")