Spring rest use of pathVariable and RequestParam

262 views Asked by At

With spring rest is there any reason to use request param?

For a search i don't know if i shoud use

@RequestMapping(value = "/lodgers/{searchParam}", method = RequestMethod.GET)
public Lodger getAllLogders(@PathVariable("searchParam") String searchParam) 

or

@RequestMapping(value = "/lodgers/", method = RequestMethod.GET)
public Lodger getAllLogders(String searchParam) 
1

There are 1 answers

0
sschrass On

As I use it, a path (pathVariables) points to a resource. A queryParam (requestParam) results in a subset of a resource.

If you want certain users from /Users (e.g. beginning with "A", or lodgers named "Curt") this would be a subset, of all /Users and I see not a very good reason for having a special resource with that criteria, so I would use a queryParam here.