A comprehensive Spring Boot REST API application demonstrating CRUD operations with MongoDB integration. This project serves as the source code for the YouTube tutorial series on building REST APIs with Spring Boot and MongoDB.
This repository is the source code for the video tutorial: Spring Boot REST API with MongoDB: CRUD Operations
- Java 21 - Programming language
- Spring Boot 3.5.6 - Application framework
- MongoDB - NoSQL database
- Maven - Build and dependency management
- Spring Web - REST API development
- Spring Data MongoDB - Data access layer
- Spring Boot Validation - Input validation
Before running this application, make sure you have the following installed:
- ☕ Java 21 or higher
- 🗄️ MongoDB (running on localhost:27017)
- 📦 Maven 3.6+
git clone https://github.com/learnwithiftekhar/REST-APIs-with-Spring-Boot-and-MongoDB.git
cd spring-mongo-repository-demoEnsure MongoDB is running on your local machine:
# Start MongoDB service (varies by OS)
# Windows: net start MongoDB
# macOS: brew services start mongodb-community
# Linux: sudo systemctl start mongodThe application connects to:
- Host: localhost
- Port: 27017
- Database: products_demo
# Build the project
mvn clean install
# Run the application
mvn spring-boot:runThe application will start on http://localhost:8080
| Method | Endpoint | Description |
|---|---|---|
| 🟢 GET | /api/products |
Get all products |
| 🟢 GET | /api/products/{id} |
Get product by ID |
| 🟡 POST | /api/products |
Create a new product |
| 🔵 PUT | /api/products/{id} |
Update existing product |
| 🔴 DELETE | /api/products/{id} |
Delete product by ID |
{
"id": "string",
"name": "string (required)",
"price": "number (required)",
"description": "string"
}curl -X POST http://localhost:8080/api/products \
-H "Content-Type: application/json" \
-d '{
"name": "Laptop",
"price": 999.99,
"description": "High-performance laptop"
}'curl -X GET http://localhost:8080/api/productscurl -X GET http://localhost:8080/api/products/{productId}curl -X PUT http://localhost:8080/api/products/{productId} \
-H "Content-Type: application/json" \
-d '{
"name": "Updated Laptop",
"price": 899.99,
"description": "Updated description"
}'curl -X DELETE http://localhost:8080/api/products/{productId}src/
├── main/
│ ├── java/com/learnwithiftekhar/spring_mongo_repository_demo/
│ │ ├── SpringMongoRepositoryDemoApplication.java
│ │ ├── controller/
│ │ │ └── ProductController.java
│ │ ├── model/
│ │ │ └── Product.java
│ │ ├── repository/
│ │ │ └── ProductRepository.java
│ │ └── service/
│ │ └── ProductService.java
│ └── resources/
│ └── application.properties
└── test/
└── java/com/learnwithiftekhar/spring_mongo_repository_demo/
└── SpringMongoRepositoryDemoApplicationTests.java
spring.application.name=spring-mongo-repository-demo
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=products_demoRun the tests using Maven:
mvn test- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Subscribe to Learn With Ifte for more programming tutorials!
- 💼 LinkedIn: Md Iftekhar Hossain
- 📧 Email: learnwithiftekhar@gmail.com
- 📰 Newsletter: Subscribe Here
This project is open source and available under the MIT License.
If you found this project helpful, please give it a ⭐ on GitHub and consider subscribing to the YouTube channel!
Happy Coding! 🚀