A simple Spring Boot REST API application for managing users with basic CRUD (Create, Read, Update, Delete) operations.
- 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
- Java 21 or higher
- Maven 3.6+
- IDE (IntelliJ IDEA, Eclipse, or VS Code)
-
Clone the repository
git clone https://github.com/joaoliveira6704/SpringBootAuthAPI.git cd crudProject -
Build the project
mvn clean install
-
Run the application
mvn spring-boot:run
Or run directly from your IDE by executing the main class:
com.joaooliveira.crudProject.CrudProjectApplication
-
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)
- JDBC URL:
- API Base URL:
-
Access the swagger-ui
- Base URL:
http://localhost:8080/swagger-ui/index.html
- Base URL:
| 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 |
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=1Update 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=1crudProject/
βββ 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
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=- 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 ofuser(reserved keyword in H2).
- 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
JoΓ£o Oliveira
This project is open source and available for educational purposes.