Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ProductAPI

A RESTful Product Management API built with Spring Boot and MongoDB.


Overview

ProductAPI is a RESTful backend API built with Spring Boot and MongoDB. It demonstrates a layered architecture by separating responsibilities into the Controller, Service, Repository, and Entity layers.


Features

  • RESTful CRUD API for product management
  • MongoDB Atlas integration using Spring Data MongoDB
  • Input validation with Jakarta Validation
  • Global exception handling with custom exceptions
  • Appropriate HTTP status codes for API responses

Tech Stack

  • Java 21
  • Spring Boot
  • Spring Data MongoDB
  • MongoDB Atlas
  • Maven

API Endpoints

Method Endpoint Description
GET /products Retrieve all products
GET /products/{id} Retrieve a product by ID
POST /products Create a new product
PUT /products/{id} Update an existing product
DELETE /products/{id} Delete a product

Screenshot

ProductAPI Screenshot

---

Postman Collection

A ready-to-use Postman collection and environment are included for testing the API.

postman/
├── ProductAPI.postman_collection.json
└── ProductAPI.postman_environment.json

After importing:

  1. Select the ProductAPI Local environment.
  2. Ensure baseUrl is set to http://localhost:8080.
  3. Set the productId variable to an existing product ID when testing endpoints that require one.


Running with Docker

Build the Docker image

mvn clean package
docker build -t productapi .

Run the container

docker run -p 8080:8080 productapi

The API will be available at:

http://localhost:8080/products

Validation

Incoming requests are validated before processing.

  • name must not be blank
  • price must be greater than 0

Exception Handling

The API uses centralized exception handling to return meaningful error responses.

Example:

{
  "message": "Product not found."
}

Prerequisites

Make sure you have the following installed/set up before running the project:

  • Java 21
  • Maven (or use the included ./mvnw wrapper)
  • A MongoDB Atlas account with a cluster and connection string

Getting Started

Clone the repository

git clone https://github.com/SiddhiikaN/ProductAPI-SpringBoot.git

Navigate to the project

cd ProductAPI-SpringBoot

Configure MongoDB

Update src/main/resources/application.properties with your MongoDB Atlas connection string before running the application.

spring.mongodb.uri = <YOUR_MONGODB_CONNECTION_STRING>

Run the application

./mvnw spring-boot:run

or

mvn spring-boot:run

About

RESTful Product API built with Spring Boot and MongoDB featuring CRUD operations.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages