Develop true restful APIs by supporting pagination, filtering, selection, sorting, and searching. This project helps you add these features to your REST Controller easily without developing custom solutions. The project is currently only compatible with Spring Data MongoDB applications. There is a blog post here, where I describe step-by-step the implementation of this library.
For Maven-based projects, add the following to your pom.xml file. This dependency is available from the Maven Central repository.
<dependency>
<groupId>com.github.apavlidi</groupId>
<artifactId>restfulQueries</artifactId>
<version>0.0.1</version>
</dependency>
- Add a RequestParam of type Map to your Rest Controller.
@GetMapping("/profile")
private List<Profile> getAllProfiles(@RequestParam Map <String, String> filters) {
....
}
- Call the collectRestApiParams() inside your controller and pass the RequestParam map.
Map<String, String> restApiQueries = collectRestApiParams(filters);
- Pass the filters to your service/repository and before calling the Spring Data MongoDB API, call applyRestApiQueries() and pass your query variable.
@Override
public List<Profile> getAllProfilesDemo(Map<String, String> filters) {
Query query = new Query();
applyRestApiQueries(query, restApiQueries);
return mongoTemplate.find(query, Profile.class);
}
Navigate to API Documentation for more
RestfulQueries documentation is available here.
The main purpose of this repository is provide an easy way of implementing truly restful apis by supporting the features of pagination, selection, filtering, and sorting to the developers. Development of RestfulQueries happens here on GitHub, and we are grateful to the community for contributing bugfixes and improvements.
Read the contributing guide to learn about the development process, how to propose bugfixes and improvements, and how to build and test your changes to RestfulQueries.
To help you get your feet wet and get you familiar with the contribution process, check the issues for good first issues that contain bugs or enhancements with relatively limited scope. This is a great place to get started.
Suggestions and/or improvements are welcome!
This project is licensed under the MIT License