Standalone Ktor server examples built with Gradle, from a minimal hello-world service to a more feature-rich REST API sample.
| Module | Purpose |
|---|---|
hello-world-server |
Smallest possible Ktor server with one route, using the CIO engine |
basic-server |
REST API example using the CIO engine, with Koin DI, JSON serialization, logging, static resources, and status pages |
advanced-server |
Will include everything from basic-server, plus a real database using Exposed/PostgreSQL and JWT authentication (coming soon). |
- JDK 21 (modules set
jvmToolchain(21)) - macOS/Linux/Windows
- Use the included Gradle wrapper (
./gradleworgradlew.bat)
Run the hello-world module:
./gradlew :hello-world-server:runThen call:
curl http://localhost:8080/api/v1/hello./gradlew :hello-world-server:run
./gradlew :basic-server:runBoth modules default to port 8080, so stop one before starting the other.
curl http://localhost:8080/api/v1/users
curl http://localhost:8080/api/v1/users/<user-id>
curl http://localhost:8080/api/v1/products
curl "http://localhost:8080/api/v1/products?query=phone"./gradlew clean build
./gradlew testBuild artifacts are generated under each module's build/libs directory.
hello-world-server/: minimal embedded CIO examplebasic-server/: multi-feature API sampleadvanced-server/: advanced sample scaffoldgradle/libs.versions.toml: centralized versions/plugins
- Port already in use: free port
8080or change module config. - Java version mismatch: check with
java -versionand use JDK 21. - Gradle oddities: run
./gradlew --stopand retry.
See LICENSE.