JDev
JDev

Reputation: 1822

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

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.

Upvotes: 1

Views: 180

Answers (1)

JB Nizet
JB Nizet

Reputation: 691765

You can use a regexp to make spring consider the two mappings as different. See the documentation.

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

Upvotes: 1

Related Questions