Work

Spring boot Reactive web flux with MongoDB

Design
Branding

A modern CRUD application using Spring boot and MongoDB. This tutorial will guide you through the process of how to create a simple CRUD application using Spring boot and MongoDB using reactive web flux for non blocking I/O.

Spring boot logo

Spring Boot Reactive CRUD with MongoDB

This project demonstrates a simple CRUD (Create, Read, Update, Delete) API implemented using Java, Spring Boot, Reactive Web Flux, and MongoDB. It provides endpoints to interact with MongoDB using reactive programming techniques.

Requirements

  • Java Development Kit (JDK) 11 or higher
  • Apache Maven
  • MongoDB

Setup

  1. Clone the repository:
    git clone https://github.com/your-username/your-project.git

Navigate to the project directory:

cd your-project

Build the project:

mvn clean install

Run the application:

 mvn spring-boot:run
 ```
The application will start on port 8080.

## Endpoints
Create a new user:
```http
POST /users

Get all users:

GET /users

Get a user by ID:

GET /users/{id}

Update a user:

PUT /users/{id}

Delete a user:

DELETE /users/{id}

Configuration

The MongoDB connection settings can be configured in application.properties file. You can specify the MongoDB URI, database name, and other properties in this file.

# MongoDB configuration
spring.data.mongodb.uri=mongodb://localhost:27017/mydatabase

Dependencies

Spring Boot Starter Web Flux: Provides reactive web support. Spring Boot Starter Data MongoDB Reactive: Enables reactive MongoDB support. Lombok: For reducing boilerplate code. Spring Boot Starter Test: For testing. Embedded MongoDB: For integration testing with an embedded MongoDB instance.

Testing

The project includes unit tests to ensure the correctness of CRUD operations. To run the tests, execute the following command:

mvn test