A modern, containerized Kotlin web application built with Ktor framework, featuring three REST API endpoints and a beautiful responsive HTML UI for interacting with the APIs.
-
Three REST API Endpoints:
GET /api/greeting- Returns a personalized greeting with timestampPOST /api/calculate- Performs arithmetic operations (add, subtract, multiply, divide)GET /api/time- Returns current server time and timezone information
-
Responsive Web UI:
- Modern, gradient-based design with glassmorphism effects
- Fully responsive (mobile and desktop)
- Interactive forms to test each API endpoint
- Real-time result display with smooth animations
-
Containerized:
- Docker support for easy deployment
- Multi-stage build for optimized image size
- Platform-specific build support (linux/amd64)
- Language: Kotlin 1.9.21
- Framework: Ktor 2.3.7
- Build Tool: Gradle 8.5
- Runtime: OpenJDK 17
- Server: Netty (embedded)
GET /api/greeting?name=YourNameResponse:
{
"message": "Hello, YourName! Welcome to Kotlin REST API.",
"timestamp": "2025-12-19T16:50:01+05:30"
}POST /api/calculate
Content-Type: application/json
{
"operation": "add",
"a": 10,
"b": 5
}Response:
{
"result": 15.0,
"operation": "add",
"expression": "10.0 + 5.0 = 15.0"
}Supported operations: add, subtract, multiply, divide
GET /api/timeResponse:
{
"currentTime": "2025-12-19 16:50:01",
"timezone": "Asia/Kolkata",
"epochMillis": 1734609601000
}Build the Docker image for linux/amd64 platform:
docker build --platform=linux/amd64 -t kotlin-docker-app .This will:
- Use Gradle to build the application
- Create a fat JAR with all dependencies
- Package it in a lightweight OpenJDK 17 runtime image
Run the container and map port 9000:
docker run -p 9000:9000 kotlin-docker-appFor running in detached mode:
docker run -d -p 9000:9000 --name kotlin-api kotlin-docker-appOnce the container is running, access the application at:
- Web UI: http://localhost:9000
- API Endpoints:
- JDK 17 or higher
- Gradle 8.5 or higher (or use the Gradle wrapper)
- Build the application:
./gradlew build- Run the application:
./gradlew runThe application will start on port 9000.
Using curl:
# Test greeting endpoint
curl "http://localhost:9000/api/greeting?name=Developer"
# Test calculator endpoint
curl -X POST http://localhost:9000/api/calculate \
-H "Content-Type: application/json" \
-d '{"operation":"multiply","a":7,"b":6}'
# Test time endpoint
curl http://localhost:9000/api/timeThe web interface provides:
- Beautiful gradient background with purple-to-violet theme
- Glassmorphism cards for each API endpoint
- Interactive forms with real-time validation
- Smooth animations and hover effects
- Responsive design that works on all screen sizes
- JSON response display with proper formatting
kotlin-docker/
├── src/
│ └── main/
│ └── kotlin/
│ └── com/
│ └── example/
│ └── Application.kt
├── build.gradle.kts
├── settings.gradle.kts
├── Dockerfile
└── README.md
This project is open source and available for educational and commercial use.