Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resteasy @path with zero or more path parameters

Tags:

java

url

resteasy

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.

like image 738
Romi Avatar asked Dec 04 '22 05:12

Romi


1 Answers

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
}
like image 169
mrjmh Avatar answered Dec 14 '22 23:12

mrjmh