https://github.com/devcavin/spring-reactive-kotlin
https://github.com/devcavin/spring-reactive-kotlin
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/devcavin/spring-reactive-kotlin
- Owner: devcavin
- Created: 2024-11-05T09:22:04.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-09-11T12:38:15.000Z (9 months ago)
- Last Synced: 2025-12-11T15:48:41.924Z (6 months ago)
- Language: Kotlin
- Size: 108 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Spring Reactive Kotlin Example
A simple **Spring Boot 3** project using **Kotlin**, **WebFlux (coroutines)**, and **H2 (R2DBC)**.
It demonstrates a clean, Kotlin-idiomatic way to build a reactive CRUD REST API.
---
## Features
- Reactive web layer with **Spring WebFlux**
- **Kotlin coroutines** instead of `Flux`/`Mono`
- **H2 (R2DBC)** in-memory database (no setup required)
- Simple **CRUD** endpoints for `User`
- Clean separation of DTOs, entities, repository, service, controller
---
## Project Structure
```
spring-reactive-kotlin/
├── build.gradle.kts # Gradle build (Kotlin DSL)
├── src/main/resources/
│ └── application.properties # Config (H2, R2DBC)
│ └── schema.sql # Creates users table
├── src/main/kotlin/com/example/demo/
│ ├── Application.kt # Main entry
│ ├── User.kt # Entity
│ ├── CreateUserRequest.kt # Request DTO and Response
│ ├── UserRepository.kt
│ ├── UserService.kt
│ └── UserController.kt
```
---
## Requirements
- JDK 17+
- Gradle (wrapper included)
---
## Run the App
```bash
./gradlew bootRun
```
The app will start at **http://localhost:8080**.
---
## API Endpoints
### Create User
```http
POST /users
Content-Type: application/json
{
"name": "Alice",
"email": "alice@example.com"
}
```
### Get All Users
```http
GET /users
```
### Get User by ID
```http
GET /users/{id}
```
### Delete User
```http
DELETE /users/{id}
```
---
## Database
We use **H2 (in-memory)** with **R2DBC**.
Schema is auto-created from [`schema.sql`](src/main/resources/schema.sql):
```sql
CREATE TABLE USERS (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(150)
);
```
The DB is wiped each time the app restarts (great for testing/learning).
---
## Next Steps
- Add **update endpoint**
- Add **tests** with `WebTestClient`
- Explore **error handling** with `@ControllerAdvice`
- Switch to a production DB (e.g., PostgreSQL R2DBC)