1

Is it possible to use RestEasy's Path annotation to get the following string:

/items.json

I was thinking something like this: /items{(\.)?format}, where format could be json, xml etc.

I would then have a method with an argument like: @PathParam("format") String format.

Thanks.

Radu
  • 1,044
  • 3
  • 12
  • 35
  • 1
    See below post http://stackoverflow.com/questions/4071008/resteasy-path-question-with-regular-expression – fmucar Mar 27 '12 at 10:49

2 Answers2

1

I managed to make the following work with my use case: item{format:(\.(json|xml))?}

I chose to make the reg exp restrictive so as not to have to handle unsupported or invalid formats inside the actual service method, but if one prefers a more general approach I think that instead of (json|xml) one can add \S+.

Radu
  • 1,044
  • 3
  • 12
  • 35
0

you might want to create two methods, one for the default type and one for the optional types but yes, your logic should work:

@Path(items.{format})
public Response getItems(@PathParam("format") String format) {

}

@Path(items)
public Response getItems() {
    return getItems("json");
}
Chris White
  • 29,949
  • 4
  • 71
  • 93
  • Problem is that I get a 404 response from the server when trying to call the service. Not sure if I'm doing something wrong, or there's a limitation from Path reg exp. – Radu Mar 27 '12 at 11:13