Linked Questions

Popular Questions

I am playing around with REST services in a Spring Boot environment. I have a question about the URI and naming conventions.

I have (currently) the following three mappings in my controller implementation...

@RequestMapping(method=RequestMethod.GET, value= "/v1/accounts")
public List<Account> getAllAccounts() {
    return accountService.getAllAccounts();

@RequestMapping(method=RequestMethod.GET, value="/v1/accounts/{accountId}")
public Account getAccount(@PathVariable int accountId) {
    return accountService.getAccount(accountId);

@RequestMapping(method=RequestMethod.GET, value="/v1/accounts/")
public Account getAccount(@RequestParam("shortName") String shortName) {
    return accountService.getAccount(shortName);

These currently "work", but I have a question/concern about the getAccount(String) method. If I simply use the path "v1/accounts", the compiler seems to be unable to differentiate this from the URI for getAllAccounts(). So, I added the trailing '/', and the request now looks like...


However, it seems like the two requests should be...




But, as already identified, changing the third request mapping to remove the trailing '/' results in compile-time errors.

Any input on either (a) how to eliminate the trailing '/' without running into compile-time errors, or (b) the advisability of incorporating the trailing '/' "just" to have both REST services exposed (I'm concerned about "what happens when the 3rd service is needed")?

Related Questions