I am using RESTEasy in my API development. My url is http://localhost:8080/project/player/M
or http://localhost:8080/project/player
it means am pasing {gender} as path param.
my problem is how to mapp this url to REST method, i use below mapping
@GET
@Path("player/{gender}")
@Produces("application/json")
but if use it, it maps for http://localhost:8080/project/player/M
but not for http://localhost:8080/project/player
.
i need a regular expression to map zero or more path parameters
Thanks.
Is there any reason this must be a path parameter and not a query string ? If you change it to use the latter, then you can use a @DefaultValue annotation.
So your code would then look like the following:
@GET
@Path("player") //example: "/player?gender=F"
@Produces("application/json")
public Whatever myMethod(@QueryParam("gender") @DefaultValue("M") final String gender) {
// your implementation here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With