A RESTful E-Commerce backend API built with Java 21 and Spring Boot 3.2.5, featuring product management, shopping cart, order processing and role-based access control.
- Product management with search and filter (by name, category, price range)
- Category management
- Shopping cart (add items, view cart)
- Order placement and order history
- Role-based access control (ADMIN and USER roles)
- REST API with proper HTTP methods and status codes
| Technology | Usage |
|---|---|
| Java 21 | Programming Language |
| Spring Boot 3.2.5 | Backend Framework |
| Spring Data JPA | Database ORM |
| Spring Security | Authentication & Authorization |
| MySQL | Relational Database |
| Hibernate | ORM Implementation |
| Lombok | Boilerplate Reduction |
| Maven | Build Tool |
src/main/java/com/book/ecommerce/
├── config/ # Security configuration
├── controller/ # REST API controllers
├── dto/ # Data Transfer Objects
├── model/ # JPA Entity classes
├── repository/ # Spring Data JPA repositories
└── service/ # Business logic
- users — stores user credentials and roles
- categories — product categories
- products — product details with category reference
- cart — user shopping cart
- cart_items — individual items in cart
- orders — placed orders
- order_items — individual items in each order
| Method | Endpoint | Access | Description |
|---|---|---|---|
| GET | /api/products |
Public | Get all products |
| GET | /api/products/{id} |
Public | Get product by ID |
| GET | /api/products/search |
Public | Search & filter products |
| POST | /api/products |
ADMIN | Add new product |
| PUT | /api/products/{id} |
ADMIN | Update product |
| DELETE | /api/products/{id} |
ADMIN | Delete product |
| Method | Endpoint | Access | Description |
|---|---|---|---|
| GET | /api/categories |
Public | Get all categories |
| POST | /api/categories |
ADMIN | Create category |
| DELETE | /api/categories/{id} |
ADMIN | Delete category |
| Method | Endpoint | Access | Description |
|---|---|---|---|
| GET | /api/cart/{userId} |
USER | View cart |
| POST | /api/cart/{userId}/add |
USER | Add item to cart |
| Method | Endpoint | Access | Description |
|---|---|---|---|
| POST | /api/orders/place/{userId} |
USER | Place order |
| GET | /api/orders/{userId} |
USER | Get order history |
- Java 21
- MySQL 8.0+
- Maven 3.x
- IntelliJ IDEA (recommended)
1. Clone the repository
git clone https://github.com/yourusername/springboot-ecommerce-api.git
cd springboot-ecommerce-api2. Create MySQL database
CREATE DATABASE ecommerce;3. Configure application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/ecommerce
spring.datasource.username=your_username
spring.datasource.password=your_password4. Run the application
mvn spring-boot:runThe app will start on http://localhost:8080
| Role | Username | Password |
|---|---|---|
| ADMIN | admin |
admin123 |
| USER | user |
user123 |
- Open Postman
- Set Authorization → Basic Auth
- Enter credentials based on the endpoint role
- Start with creating a category, then a product, then add to cart and place an order
POST http://localhost:8080/api/categories
Authorization: Basic Auth (admin / admin123)
Content-Type: application/json
{
"name": "Electronics",
"description": "Electronic items"
}
POST http://localhost:8080/api/products
Authorization: Basic Auth (admin / admin123)
Content-Type: application/json
{
"name": "iPhone 15",
"description": "Apple smartphone",
"price": 79999,
"stockQuantity": 10,
"imageUrl": "iphone.jpg",
"categoryId": 1
}
Manish Siddhantham