Version 5

    @PathParam

     

    @PathParam is a parameter annotation which allows you to map variable URI path fragments into your method call.

     

    @Path("/library")
    public class Library {
    
       @GET
       @Path("/book/{isbn}")
       public String getBook(@PathParm("isbn") String id) {
          // search my database and get a string representation and return it
       }
    }
    

     

    What this allows you to do is embed variable identification within the URIs of your resources.  In the above example, an isbn URI parameter is used

    to pass information about the book we want to access.  The parameter type you inject into can be any primitive type, a String, or any Java object that has

    a constructor that takes a String parameter, or a static valueOf method that takes a String as a parameter.  For example, lets say we wanted isbn to be a real object.  We could do:

     

    
       @GET
       @Path("/book/{isbn}")
       public String getBook(@PathParm("isbn") ISBN id) {...}
    
    
       public class ISBN {
          public ISBN(String str) {...}
       }
    
    

     

    Or instead of a public String constructors, have a valueOf method:

     

      public class ISBN {
         
         public static ISBN valueOf(String isbn) {...}
      }