A modern RESTful API built with Kotlin and Spring Boot demonstrating best practices.
- RESTful API with proper response handling
- Layered architecture (Controller, Service, Repository)
- Entity relationships with JPA
- Exception handling
- CORS configuration
- Database integration (H2 in-memory)
- API documentation
- Data Transfer Objects (DTOs)
- Transactional operations
- Lombok integration for reduced boilerplate
- Kotlin 1.9.0
- Spring Boot 3.1.0
- Spring Data JPA
- H2 Database
- Gradle with Kotlin DSL
- JDK 17 or later
- Gradle 7.6+ (or use the included Gradle wrapper)
- Clone the repository
- Navigate to the project directory
- Run with Gradle:
./gradlew bootRunOr on Windows:
gradlew.bat bootRunThe application will be available at http://localhost:8080
| Method | URL | Description |
|---|---|---|
| GET | /api/v1/users | Get all users |
| GET | /api/v1/users/{id} | Get user by ID |
| POST | /api/v1/users | Create a new user |
| PUT | /api/v1/users/{id} | Update an existing user |
| DELETE | /api/v1/users/{id} | Delete a user |
| GET | /api/v1/users/search | Search users by name |
| GET | /api/v1/users/recent | Get recently added users |
The H2 console is enabled and available at http://localhost:8080/h2-console
- JDBC URL:
jdbc:h2:mem:testdb - Username:
sa| Password: blank
src/
├── main/
│ ├── kotlin/
│ │ └── com/
│ │ └── example/
│ │ ├── Application.kt
│ │ ├── AppConfig.kt
│ │ ├── User.kt
│ │ ├── UserController.kt
│ │ ├── UserDto.kt
│ │ ├── UserRepository.kt
│ │ ├── UserService.kt
│ │ └── GlobalExceptionHandler.kt
│ └── resources/
│ └── application.properties
└── test/
└── kotlin/
└── com/
└── example/
└── UserControllerTests.kt
-
Architecture
- Separation of concerns (Controller, Service, Repository)
- Use of interfaces for loose coupling
- Proper exception handling
-
API Design
- RESTful principles
- Proper HTTP status codes
- DTOs for request/response separation
-
Kotlin Best Practices
- Immutable data classes
- Extension functions
- Null safety
- Function expressions
-
Performance
- JPA optimizations
- Transaction management
- Connection pooling
-
Security
- CORS configuration
- Input validation
- Error handling without exposing sensitive information
This project is licensed under the MIT License