title: Best practice determine passed parameter type in Restful API?
body: <p>I am doing my first JSON RESTful API in Java. </p>
  
  <p>The front end will be AngularJS. For the Web Service, I'm using Tomcat 7, JAX-RS, Jackson, Jersey, etc... </p>
  
  <p>I would like to keep the API as simple as possible. </p>
  
  <p>e.g. I would query a user by ID as well as UUID. So I would like to use e.g. <code>/rest/users/{id}</code> and <code>/rest/users/{uuid}</code>. I would ideally like the back-end to figure out which is which rather than create separate API branches. </p>
  
  <p>Since it's all coming from JSON, I assume I can not just let Java figure it out based on the type. So I have come up with:</p>
  
  <pre><code>@GET
  @Path("{id}")
  @Produces(MediaType.APPLICATION_JSON)
  public User getJSONUser(@PathParam("id") String id) {
  
      User user;
      if(id.contains("-")){
          user = userDao.getUserByHandle(id);
      }else{
          user = userDao.getUserById(Long.parseLong(id)); 
      }       
      return user;
  }
  </code></pre>
  
  <p>I notice that as an example, the Facebook API does this all over the place. e.g. <code>/{user-id}/albums</code> and  <code>/{page-id}/albums</code>.</p>
  
  <p>Is there some trick I should be aware of that makes detecting these parameters easier? Or is FB encoding something in the ID itself? i.e. am I on the right track already. It's pretty cool how Jersey is able to figure out the calls based on MediaType. I thought there might be something equally as cool going on inside to deal with this...</p>
  
  <p>Thanks in advance
  Peter</p>