Skip to content

saturnnode/spring-boot-crud-api-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Spring Boot CRUD API Demo

A comprehensive REST API demonstration project built with Spring Boot 3.x, showcasing full CRUD operations with modern Java enterprise technologies.

πŸ“‹ Project Overview

This project serves as a technical validation and learning demonstration for Spring Boot API development, implementing a complete User management system with best practices.

πŸ› οΈ Tech Stack

Technology Version Purpose
Java 17 (LTS) Programming Language
Spring Boot 3.5.6 Framework
Spring Data JPA 3.x Data Access Layer
Jakarta EE 9+ Enterprise Specifications
Maven 3.9.11 Build Tool
MySQL 8.x Database
Hibernate 6.x ORM Framework

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Controller    │────│    Service      │────│   Repository    β”‚
β”‚   (REST API)    β”‚    β”‚ (Business Logic)β”‚    β”‚  (Data Access)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β”‚                       β”‚                       β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   HTTP Client   β”‚    β”‚   Validation    β”‚    β”‚     MySQL       β”‚
β”‚   (Postman)     β”‚    β”‚   Error Handle  β”‚    β”‚   Database      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🎯 Features

βœ… Complete CRUD Operations

  • CREATE - Add new users with validation
  • READ - Retrieve all users or specific user by ID
  • UPDATE - Modify existing user information
  • DELETE - Remove users from database

πŸ›‘οΈ Advanced Features

  • Input Validation - Username and email validation
  • Duplicate Prevention - Username uniqueness check
  • Error Handling - Comprehensive exception management
  • HTTP Status Codes - Proper REST API responses
  • Service Layer - Business logic separation

πŸ“‘ API Endpoints

Method Endpoint Description Response
GET /users Get all users 200 OK
GET /users/{id} Get user by ID 200 OK / 404 Not Found
POST /users Create new user 200 OK / 400 Bad Request
PUT /users/{id} Update user 200 OK / 404 Not Found
DELETE /users/{id} Delete user 200 OK / 404 Not Found

πŸ“ Request/Response Examples

Create User (POST /users)

{
    "username": "john_doe",
    "name": "John Doe",
    "email": "john@example.com"
}

Response

"User created successfully with ID: 1"

πŸš€ Quick Start

Prerequisites

  • Java 17+ installed
  • Maven 3.6+ installed
  • MySQL 8.x running
  • Git installed

1. Clone Repository

git clone https://github.com/YOUR_USERNAME/spring-boot-crud-api-demo.git
cd spring-boot-crud-api-demo

2. Database Setup

CREATE DATABASE crash_api_course;

3. Configuration

Update src/main/resources/application.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/crash_api_course
spring.datasource.username=YOUR_USERNAME
spring.datasource.password=YOUR_PASSWORD

4. Run Application

# Using Maven Wrapper (Recommended)
./mvnw spring-boot:run

# Using installed Maven
mvn spring-boot:run

5. Test API

Application will start on http://localhost:8080

πŸ§ͺ Testing with Postman

Import Collection

  1. Open Postman
  2. Import the following collection:
{
    "info": { "name": "Spring Boot CRUD API" },
    "variable": [{ "key": "baseUrl", "value": "http://localhost:8080" }],
    "item": [
        {
            "name": "Get All Users",
            "request": { "method": "GET", "url": "{{baseUrl}}/users" }
        },
        {
            "name": "Create User",
            "request": {
                "method": "POST",
                "url": "{{baseUrl}}/users",
                "header": [{ "key": "Content-Type", "value": "application/json" }],
                "body": {
                    "mode": "raw",
                    "raw": "{\"username\":\"alice\",\"name\":\"Alice Smith\",\"email\":\"alice@example.com\"}"
                }
            }
        }
    ]
}

πŸ“ Project Structure

src/
β”œβ”€β”€ main/
β”‚   β”œβ”€β”€ java/com/saturn/crash_api_course/
β”‚   β”‚   β”œβ”€β”€ CrashApiCourseApplication.java     # Main Application
β”‚   β”‚   β”œβ”€β”€ controller/
β”‚   β”‚   β”‚   └── UserController.java            # REST Controllers
β”‚   β”‚   β”œβ”€β”€ service/
β”‚   β”‚   β”‚   └── UserService.java               # Business Logic
β”‚   β”‚   β”œβ”€β”€ repository/
β”‚   β”‚   β”‚   └── UserRepository.java            # Data Access
β”‚   β”‚   └── model/
β”‚   β”‚       └── User.java                      # JPA Entities
β”‚   └── resources/
β”‚       └── application.properties             # Configuration
└── test/
    └── java/
        └── CrashApiCourseApplicationTests.java # Tests

πŸ” Learning Objectives

This project demonstrates:

  • βœ… Spring Boot 3.x modern features
  • βœ… RESTful API design principles
  • βœ… 3-Layer Architecture (Controller-Service-Repository)
  • βœ… JPA/Hibernate ORM usage
  • βœ… Dependency Injection patterns
  • βœ… Input Validation best practices
  • βœ… Error Handling strategies
  • βœ… HTTP Status Codes proper usage
  • βœ… Maven build management

πŸ› οΈ Development Tips

Database Connection Test

mysql -u root -p -e "SELECT 1;"

Check Application Logs

tail -f logs/spring-boot-application.log

Maven Commands

# Clean and compile
./mvnw clean compile

# Run tests
./mvnw test

# Package JAR
./mvnw clean package

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages