Spring Data Rest provides a very simple option to expose CRUD RESTful services around data repositories.
Some of the important features of Spring Data Rest include the following:
- Exposing the REST API around Spring Data repositories
- Support for pagination and filtering
- Understanding query methods in Spring Data repositories and exposing them as search resources
- Among the frameworks supported are JPA, MongoDB, and Cassandra
- Options to customize the resources are exposed by default
We will start by including the Spring Boot Data Rest starter in our pom.xml
:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-rest</artifactId> </dependency>
We can make UserRepository
expose the REST service by adding a simple annotation, as shown in the following snippet:
@RepositoryRestResource(collectionResourceRel = "users", path = "users") public interface UserRepository extends PagingAndSortingRepository...