This project is a RESTful API built with Spring Boot 3 and MongoDB. It provides a foundation for building document-oriented applications with full CRUD operations. The project includes a product management system with search capabilities.
To run this application, you need:
- Java 17 or higher
- MongoDB (running locally on port 27017)
- Gradle 8
Our application uses these key technologies:
-
Java - The core programming language with modern features like records and improved switch expressions.
-
Spring Boot - A framework that simplifies Java application development with convention over configuration.
-
Spring Data MongoDB - Provides integration with MongoDB database and implements repository pattern.
-
MongoDB - A NoSQL document database that stores data in flexible, JSON-like documents.
-
Gradle - A build automation tool that manages dependencies and builds the application.
-
Lombok - A Java library that reduces boilerplate code with annotations.
The application is configured through the application.yaml
file:
spring:
data:
mongodb:
host: localhost
port: 27017
database: mydatabase
server:
port: 8080
logging:
level:
org:
springframework:
data:
mongodb:
core:
MongoTemplate: DEBUG
Configuration fields:
spring.data.mongodb.host
: MongoDB server hostnamespring.data.mongodb.port
: MongoDB server portspring.data.mongodb.database
: Database nameserver.port
: Application server portlogging.level
: Logging configuration for MongoDB operations
- Ensure MongoDB is running locally on port 27017
- Start the application:
./gradlew bootRun
Here are some curl commands to test the application:
curl -X POST http://localhost:8080/api/products \
-H "Content-Type: application/json" \
-d '{"name":"MongoDB Book","description":"A guide to MongoDB","price":29.99}'
curl http://localhost:8080/api/products
curl http://localhost:8080/api/products/YOUR_PRODUCT_ID
curl -X PUT http://localhost:8080/api/products/YOUR_PRODUCT_ID \
-H "Content-Type: application/json" \
-d '{"name":"Updated Book","description":"Revised guide","price":34.99}'
curl "http://localhost:8080/api/products/search?name=Book"
curl "http://localhost:8080/api/products/search?maxPrice=30"
curl -X DELETE http://localhost:8080/api/products/YOUR_PRODUCT_ID
For more detailed information, please visit the wiki.