pathjax-rsuritemplate

JAX-RS Path annotation URI template


I have this code method in a java class with JAX-RS:

import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;

@Path("/reports/{id: (zerotrips|notrips|tripsummary|rejectedtrips){1}/{0,1}}")
@GET
public Response get(@Context HttpServletRequest aRequest){
   ....
}

Could someone give some examples of the url mapped by the expression in the @Path annotation?


Solution

  • /reports/zerotrips
    /reports/zerotrips/
    

    Replace zerotrips with any of the other ones on between the parenthesis

    (zerotrips|notrips|tripsummary|rejectedtrips){1}
    

    This says any one of the values in the parenthesis. | means "or". The {1} means "once".

    /{0,1}
    

    means with or without a slash. {0,1} means zero to once.

    A pattern followed by {} gives the number of times it is allowed. For example a{3,5} means an a three to five times. So the following would match: aaa, aaaa, aaaaa, but aa would not match.