title: Spring REST controller with different functions
body: <p>I have a Spring <code>@RestController</code> for manipulating my Users and I want to have several functions:<br></p>
  
  <ul>
  <li>/users : GET (returns all users)</li>
  <li>/users/:id : GET (returns a user with given ID, default id=1)</li>
  <li>/users : POST (inserts a user)</li>
  <li>/users/:id : DELETE (deletes a user with given ID)</li>
  </ul>
  
  <p>I started working on it but I'm not sure how to manage the "overlapping" URIs for the same method (e.g. first two cases). Here's what I came with so far:<br></p>
  
  <pre><code>@RestController
  public class UserController {
      @RequestMapping(value = "/users", method = RequestMethod.GET)
      public List&lt;User&gt; getAllUsers() {
          return UserDAO.getAll();
      }
  
      @RequestMapping(value = "/users", method = RequestMethod.GET)
      public User getUser(@RequestParam(value = "id", defaultValue = "1") int id) {
          return UserDAO.getById(id);
      }
  }
  </code></pre>
  
  <p>This won't work due to "ambiguous mapping" and it's pretty clear to me, but I don't know what to do. Should I change one of the URIs or there is some other way?</p>
  
  <p>Edit: 
  I've also tried changing the second method to:</p>
  
  <pre><code>@RequestMapping(value = "/users/{id}", method = RequestMethod.GET)
  public User getUser(@PathVariable("id") int id) {
      return UserDAO.getById(id);
  }
  </code></pre>
  
  <p>Still doesn't work.</p>