Book Image

RESTful Java Web Services, Second Edition

Book Image

RESTful Java Web Services, Second Edition

Overview of this book

Table of Contents (17 chapters)
RESTful Java Web Services Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing search and sort operations


Allowing a client to perform the search and sort operations on a resource collection is very essential to improve the market adoption of your APIs. As there is no existing standard for passing sort criteria or search conditions, various API vendors follow different patterns. A very common approach is to pass the search and sort criteria as the query parameters to the server.

The following example illustrates how you can pass the search criteria as the query parameters to the server:

/employees?departmentName=hr&salary>500000

The query parameters present in the preceding resource request URI can be used by the RESTful API implementation to find out the employee resources belonging to the HR department whose annual salary is greater than 500000.

Similarly, to read the collection of resources in a sorted order, you can pass the sort criteria as the query parameter to the API. The following example uses the sort keyword as the query parameter to indicate...