Search code examples
javarestjerseyjax-rs

Regarding optional path in JAX-RS


I want to pass an optional parameter in the JAX-RS path.I am using the below path but its not working.

@Path("/lock/{userName}/{userid:(([a-zA-Z]{2})?)}")

The resource should get invoked for both with userid and without user id parameter in the path. Can anyone suggest me what needs to be done?

Thanks


Solution

  • You could take out the / between the two template parameters and insert it into the regex of the userId

    @Path("/lock/{userName}{userid:((/[a-zA-Z]{2})?)}")
    

    Won't make a difference, but the extra wrapping parenthesis are not needed,
    i.e. this {userid: (/[a-zA-Z]{2})?} is sufficient