JAX-RS: @QueryParam and @PathParam

Leave a comment

April 2, 2012 by huionn

Query Parameters (@QueryParam):
used to extract query parameters from the Query component of the request URL

Path Parameters (@PathParam):
used to extract method parameter of a request method

(more info: http://jersey.java.net/nonav/documentation/latest/user-guide.html)

There is no hard rule to choose between @QueryParam and @PathParam. However I think it makes sense to use @QueryParam for mandatory parameters and @PathParam for optional parameters (0, 1 or  N). In addition, this will make client implementation slightly simpler.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: