
Overview
The Ecommerce API is a production-ready RESTful web service built with Spring Boot 4.0.1 that provides comprehensive functionality for managing online retail operations. This API implements HATEOAS principles, offering hypermedia-driven interactions that make navigation and resource discovery intuitive for client applications. Designed for scalability and maintainability, the API handles everything from product catalog management and user authentication to shopping cart operations and category organization.Quickstart
Get up and running in minutes with our step-by-step guide
API Reference
Explore all available endpoints and their parameters
Authentication
Learn how to secure API requests with Spring Security
Data Models
Browse data structures and entity relationships
What Can You Build?
The Ecommerce API provides the backend infrastructure for a wide range of online retail applications:- Product Catalogs - Manage products with detailed information including pricing, descriptions, stock levels, and multi-category classification
- User Management - Handle customer accounts with secure authentication and role-based access control
- Shopping Carts - Enable customers to add items, calculate totals with automatic discount application, and manage quantities
- Category Management - Organize products into flexible category structures with many-to-many relationships
- Inventory Tracking - Monitor stock quantities and availability in real-time
Key Features
HATEOAS-Compliant REST API
HATEOAS-Compliant REST API
Every resource response includes hypermedia links that guide API consumers to related resources and available actions. This self-documenting approach reduces coupling between client and server.Implemented using Spring HATEOAS with
EntityModel and CollectionModel wrappers that automatically generate relevant links based on controller methods.JPA/Hibernate Data Persistence
JPA/Hibernate Data Persistence
Leverages Spring Data JPA with Hibernate as the ORM provider for seamless database operations. Supports both PostgreSQL for production and H2 for development/testing.Features include:
- Automatic schema generation
- Entity relationships with cascading operations
- Auditing with
@CreatedDateand@UpdateTimestamp - Transaction management
Pagination Support
Pagination Support
Built-in pagination for large result sets using Spring Data’s
Pageable interface. Default page size of 20 items with a maximum of 50 items per page.Product listings return PagedModel responses containing navigation metadata (page number, total pages, total elements) and HATEOAS links for next/previous pages.Spring Security Integration
Spring Security Integration
Implements authentication and authorization with password encryption using BCrypt. User entities support role-based access control with
Role.CUSTOMER and extensible role definitions.Security configuration can be customized via SecurityConfig class.Input Validation
Input Validation
Uses Jakarta Bean Validation annotations (
@Min, @NotNull, etc.) to ensure data integrity. Validation occurs automatically at the controller layer with descriptive error messages.Cart totals must be non-negative, stock quantities are validated, and required fields are enforced at the database level.Flexible Product Categorization
Flexible Product Categorization
Products can belong to multiple categories through a many-to-many relationship implemented with the join entity
ProductCategory. Categories are created dynamically during product creation if they don’t exist.This architecture supports complex catalog structures like products appearing in both “Electronics” and “Sale Items” categories simultaneously.Technology Stack
The API is built on a modern, proven technology foundation:Spring Boot
Version 4.0.1 with auto-configuration and embedded Tomcat server
Java
Java 17 with modern language features
Maven
Dependency management and build automation
PostgreSQL
Production-grade relational database
H2 Database
In-memory database for development
Hibernate
JPA implementation for ORM
Lombok
Reduces boilerplate with annotations
Spring HATEOAS
Hypermedia support for REST APIs
Spring Security
Authentication and authorization
Architecture Highlights
Entity Structure
The API uses a well-designed domain model with proper relationships:- Product - Core entity with id, name, description, price, stockQuantity, discount, and timestamps
- User - Customer accounts with email, password (encrypted), role, and creation date
- Category - Product classification with name and relationships
- ProductCategory - Join entity enabling many-to-many product-category relationships
- Cart - Shopping cart with automatic total/discount calculation
- CartItems - Individual items within a cart
Resource Representation
Controllers expose resources following REST conventions:GET /products- Paginated product listing with HATEOAS linksGET /products/{id}- Individual product detailsPOST /products- Create new products with category assignmentPUT/PATCH /products/{id}- Update existing productsDELETE /products/{id}- Remove productsGET /users- User collectionGET /categories- Category listing
Data Preloading
TheDatabasePreLoader component initializes the database with sample data on startup:
- Two user accounts for testing
- Sample products (Laptop, Smartphone) in the Electronics category
- Proper entity relationships established
The preloader runs automatically via Spring’s
CommandLineRunner interface, making it easy to get started with test data.Next Steps
Get Started
Follow our quickstart guide to run your first API request
Explore Endpoints
Dive into the complete API reference documentation
