A simple RESTful API for managing users, built with Spring Boot, H2 Database, and implementing a layered architecture.
- Java 21
- Spring Boot 3.4.2
- Spring Data JPA
- H2 Database (In-Memory)
- Lombok
- Maven
- JDK 21 installed (
java -version) - Git installed
-
Clone the repository
git clone https://github.com/dwisusanto007/java-user-crud-api.git cd java-user-crud-api -
Build the project
./mvnw clean package
Run the application using the Maven wrapper:
./mvnw spring-boot:runThe application will start on http://localhost:8080.
| Method | Endpoint | Description | Request Body Example |
|---|---|---|---|
GET |
/api/users |
List all users | - |
GET |
/api/users/{id} |
Get user by ID | - |
POST |
/api/users |
Create a new user | {"name": "John", "email": "john@example.com"} |
PUT |
/api/users/{id} |
Update a user | {"name": "Jane", "email": "jane@example.com"} |
DELETE |
/api/users/{id} |
Delete a user | - |
The API documentation is available via Swagger UI:
Note: If port 8080 is in use, check the console output for the actual port (e.g., 8081).
Application logs are written to a file named app.log in the root directory.
- Log File:
./app.log - Configuration:
logging.file.name=app.loginapplication.properties
To run the automated tests (Unit & Integration):
./mvnw clean testsrc/main/java/com/antigravity/user_api/
├── controller/ # Web Layer (API Endpoints)
├── service/ # Business Logic
├── repository/ # Data Access Layer
├── entity/ # Database Models
├── dto/ # Data Transfer Objects
└── exception/ # Global Exception Handling
Since this project uses H2 In-Memory database, you can access the database console at:
- URL: http://localhost:8080/h2-console
- JDBC URL:
jdbc:h2:mem:testdb - Username:
sa - Password:
password