Skip to content

learnwithiftekhar/REST-APIs-with-Spring-Boot-and-MongoDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Spring Boot REST API with MongoDB

Spring Boot Java MongoDB Maven

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.

📺 Video Tutorial

This repository is the source code for the video tutorial: Spring Boot REST API with MongoDB: CRUD Operations

🛠️ Technology Stack

  • 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

📋 Prerequisites

Before running this application, make sure you have the following installed:

  • Java 21 or higher
  • 🗄️ MongoDB (running on localhost:27017)
  • 📦 Maven 3.6+

🚀 Getting Started

1. Clone the Repository

git clone https://github.com/learnwithiftekhar/REST-APIs-with-Spring-Boot-and-MongoDB.git
cd spring-mongo-repository-demo

2. Configure MongoDB

Ensure 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 mongod

The application connects to:

  • Host: localhost
  • Port: 27017
  • Database: products_demo

3. Build and Run

# Build the project
mvn clean install

# Run the application
mvn spring-boot:run

The application will start on http://localhost:8080

📡 API Endpoints

Product Management

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

Product Model

{
  "id": "string",
  "name": "string (required)",
  "price": "number (required)",
  "description": "string"
}

🧪 API Usage Examples

Create a Product

curl -X POST http://localhost:8080/api/products \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Laptop",
    "price": 999.99,
    "description": "High-performance laptop"
  }'

Get All Products

curl -X GET http://localhost:8080/api/products

Get Product by ID

curl -X GET http://localhost:8080/api/products/{productId}

Update a Product

curl -X PUT http://localhost:8080/api/products/{productId} \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Updated Laptop",
    "price": 899.99,
    "description": "Updated description"
  }'

Delete a Product

curl -X DELETE http://localhost:8080/api/products/{productId}

🏗️ Project Structure

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

⚙️ Configuration

Application Properties

spring.application.name=spring-mongo-repository-demo
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=products_demo

🧪 Testing

Run the tests using Maven:

mvn test

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📚 Learn More

📺 YouTube Channel

Subscribe to Learn With Ifte for more programming tutorials!

🔗 Connect With Me

📄 License

This project is open source and available under the MIT License.

⭐ Support

If you found this project helpful, please give it a ⭐ on GitHub and consider subscribing to the YouTube channel!


Happy Coding! 🚀

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages