Skip to content

A simple Spring Boot REST API application for managing users with basic CRUD (Create, Read, Update, Delete) operations.

Notifications You must be signed in to change notification settings

joaoliveira6704/SpringBootAuthAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 

Repository files navigation

CRUD Project

A simple Spring Boot REST API application for managing users with basic CRUD (Create, Read, Update, Delete) operations.

πŸš€ Technologies Used

  • Java 21
  • Spring Boot 3.5.6
  • Spring Data JPA - Database access layer
  • H2 Database - In-memory database
  • Lombok - Reduce boilerplate code
  • Maven - Dependency management

πŸ“‹ Prerequisites

  • Java 21 or higher
  • Maven 3.6+
  • IDE (IntelliJ IDEA, Eclipse, or VS Code)

πŸ› οΈ Installation & Setup

  1. Clone the repository

    git clone https://github.com/joaoliveira6704/SpringBootAuthAPI.git
    cd crudProject
  2. Build the project

    mvn clean install
  3. Run the application

    mvn spring-boot:run

    Or run directly from your IDE by executing the main class:

    com.joaooliveira.crudProject.CrudProjectApplication
  4. Access the application

    • API Base URL: http://localhost:8080
    • H2 Console: http://localhost:8080/h2-console
      • JDBC URL: jdbc:h2:mem:user
      • Username: sa
      • Password: (leave empty)
  5. Access the swagger-ui

    • Base URL: http://localhost:8080/swagger-ui/index.html

πŸ“‘ API Endpoints

User Management

Method Endpoint Description
POST /users Create a new user
GET /users Get all users
GET /users?id={id} Get user by email
PUT /users?id={id} Update user by ID
DELETE /users?id={id} Delete user by ID

Example Requests

Create a new user:

POST http://localhost:8080/users
Content-Type: application/json

{
  "name": "John Doe",
  "email": "[email protected]"
}

Get user by id:

GET http://localhost:8080/users?id=1

Update a user:

PUT http://localhost:8080/users?id=1
Content-Type: application/json

{
  "name": "John Smith",
  "email": "[email protected]"
}

Delete a user:

DELETE http://localhost:8080/users?id=1

πŸ—‚οΈ Project Structure

crudProject/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/
β”‚   β”‚   β”œβ”€β”€ java/
β”‚   β”‚   β”‚   └── com/joaooliveira/crudProject/
β”‚   β”‚   β”‚       β”œβ”€β”€ business/          # Service layer
β”‚   β”‚   β”‚       β”œβ”€β”€ controller/        # REST controllers
β”‚   β”‚   β”‚       β”œβ”€β”€ infrastructure/
β”‚   β”‚   β”‚       β”‚   β”œβ”€β”€ entities # Entities layer
β”‚   β”‚   β”‚       β”‚   β”œβ”€β”€ repository # Repository layer
β”‚   β”‚   β”‚       └── CrudProjectApplication.java
β”‚   β”‚   └── resources/
β”‚   β”‚       └── application.properties
β”‚   └── test/
└── pom.xml

πŸ”§ Configuration

The application uses H2 in-memory database by default. Configuration is in application.properties:

# H2 Database
spring.application.name=crudProject
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.datasource.url=jdbc:h2:mem:user
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=

⚠️ Important Notes

  • No Authentication: This is a basic CRUD application without security. All endpoints are publicly accessible.
  • In-Memory Database: Data is lost when the application stops. For persistence, switch to PostgreSQL/MySQL.
  • Table Name Issue: If you encounter SQL syntax errors, ensure your entity uses @Table(name = "users") instead of user (reserved keyword in H2).

🚧 Future Enhancements

  • Add JWT authentication and authorization
  • Add email search
  • Add input validation
  • Add pagination for list endpoints
  • Switch to PostgreSQL for production
  • Add unit and integration tests
  • Add exception handling
  • Add logging

πŸ‘€ Author

JoΓ£o Oliveira

πŸ“„ License

This project is open source and available for educational purposes.

About

A simple Spring Boot REST API application for managing users with basic CRUD (Create, Read, Update, Delete) operations.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages