In this recipe, we will see how to access MongoDB and perform CRUD operations using REST APIs. We will use spring-data-rest
for REST access and spring-data-mongodb
to perform the CRUD operations. Before you continue with this recipe, it is important to know how to implement CRUD repositories using spring-data-mongodb
. Refer to the Developing using spring-data-mongodb recipe to know how to use this framework.
The question that one must have is, why a REST API is needed? There are scenarios where there is a database that is being shared by many applications, possibly written in different languages. Writing JPA DAO or using spring-data-mongodb
is good enough for Java clients, but not for clients in other languages. Having APIs locally with the application doesn't even give us a centralized way to access the database. This is where REST APIs come into play. We can develop the server-side data access layer, which is the CRUD repository in Java (spring-data-mongodb
to...