In this article, we will see difference between PathParam and QueryParam and how to decide whether to use PathParam vs QueryParam in rest api design.
Diff between PathParam and QueryParam
Path params are part of the url where as query parameters are added after the ? mark symbol and separated from other query parameters by & symbol.
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
Path param example
Finding employee with ID = 12345
Query param example
Finding active employees with title as developer
Both Path params and Query params
© 2019, www.topjavatutorial.com. All rights reserved. On republishing this post, you must provide link to original post