A demo project to develop a REST API using Spring Webflux and Spring Reactive Mongo. The aim is to apply reactive programming paradigm in Java with Spring.
- Test Driven Development is adopted in this project.
- Both MVC and functional routes are used to handle requests.
- MVC controllers handle the requests to the endpoints starting with api/v1 while functional routes deal with the requests to the endpoints starting with api/v2
- MongoDb is used to persist data.
- For the reactive mongo configurations and usage visit this blog page: going reactive with spring data
- Mongo Express is used to manage database visually.
- A docker-compose.yml file for containerization.
- Using the command docker-compose up will handle creating container from the images.
- Sensitive data related to database connection is kept in .env file in the original project, but here we have .env.example.
- .env.example file is used just to represent how to create a .env file for this project. Create a file named .env and put the content similar to the .env.example so that your spring boot application and docker-compose.yml can see those variables.
The endpoints are as follows:
Endpoint | Method | Function |
---|---|---|
GET | Fetch all products | |
GET | Fetch product by id | |
POST | Create a new product | |
PUT | Update product by id | |
DELETE | Delete product by id |
Mongo Express will run on "http://localhost:8081/". Mongo Express uses HTTP Basic Authentication. The default username is admin and the default password is pass (see: mongo express on gitHub). Under the collection called "product" we store the data as documents. When visiting "http://localhost:8081/db/productDB/product", we will see:
As well as testing the app via code, functionality of the API is tested by using Postman: