I am newbie in RESTful jersey. I would like to ask what is the different between @PathParam
and @QueryParam
in jersey?
PathParam could be used to drill down to entity class hierarchy. Whereas, QueryParam could be reserved for specifying attributes to locate the instance of a class.
The @PathVariable annotation is used for data passed in the URI (e.g. RESTful web services) while @RequestParam is used to extract the data found in query parameters. These annotations can be mixed together inside the same controller. @PathParam is a JAX-RS annotation that is equivalent to @PathVariable in Spring.
@QueryParam is a JAX-RS framework annotation and @RequestParam is from Spring. QueryParam is from another framework and you are mentioning Spring. @Flao wrote that @RequestParam is from Spring and that should be used in Spring MVC.
An HTTP form can be submitted by different methods like GET and POST. @QueryParam : Accepts GET request and reads data from query string. EX. @FormParam: Accepts POST request and fetches data from HTML form or any request of the media type application/x-www-form-urlencoded.
Query parameters are added to the url after the ? mark, while a path parameter is part of the regular URL. In the URL below tom could be the value of a path parameter and there is one query parameter with the name id and value . Font Size... Font Family...
PathParam and @QueryParam both are the JAX-RS API. For more detail, find the URL. Query parameters are added to the url after the ? mark, while a path parameter is part of the regular URL.
The @PathVariable annotation is used for data passed in the URI (e.g. RESTful web services) while @RequestParam is used to extract the data found in query parameters.
When to use @PathParam vs @QueryParam. This is not a standard, you can use anyone for designing restful api. However, the commonly used convention is : Any required or mandatory attributes should be added as path param. Any optional attributes should be added as query param. params used for filtering data are usually used as query param.
Query parameters are added to the url after the ?
mark, while a path parameter is part of the regular URL.
In the URL below tom
could be the value of a path parameter and there is one query parameter with the name id
and value 1
:
http://mydomain.com/tom?id=1
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