Command line
Download the native CLI to serve files, respond with JSON or run a Kotlin application.
Serve JSON from the terminal
Download the native CLI and serve a JSON response from standard input.
Install it
Choose a download for your platform or use the terminal commands below.
HTTP
macOS may ask you to approve the ad hoc signed executable on first launch. Apple’s first-launch guidance
Direct HTTPS
The HTTPS downloads use the system’s OpenSSL 3 libraries. On Ubuntu 24.04, install libssl3t64 if needed. They can also serve plain HTTP.
Run it
Paste both lines into Bash or zsh in an empty directory. They download ./ktserve and serve the status JSON at /.
curl -fsSL https://github.com/christian-draeger/ktserve/releases/download/cli-preview-0.1.7/ktserve-cli-preview-0.1.7-linux-x86_64 -o ktserve && chmod +x ktserve &&
./ktserve serve - <<<'{"status":"ok"}'
After a browser download, name the file ktserve, run chmod +x ktserve and use the second line.
In a POSIX shell, use printf '%s\n' '{"status":"ok"}' | ./ktserve serve - as the second line.
Test it
Request the response from a second terminal.
curl -fsS http://127.0.0.1:8080/
Run Kotlin from the terminal
The downloaded CLI includes the build project. Use a Gradle-compatible JDK such as JDK 21 on Linux x86-64 or Apple Silicon macOS. On macOS, the build uses full Xcode.
./ktserve run - <<<'get("/health") { text("ok") }'
The first build may download pinned Gradle and Kotlin/Native components. The compiled server runs without a JVM and listens on 127.0.0.1:8080 by default. Test it from a second terminal.
curl -fsS http://127.0.0.1:8080/health
If port 8080 is in use, prefix the short form with PORT=8081 and use that port for the test. On Linux ARM64, use the JSON and file-serving commands.
Configure the server in Kotlin
Use run --app - to pass the full serve call with its own host, port, or ServerLimits.
./ktserve run --app - <<'KOTLIN'
serve(port = 8081, host = "127.0.0.1") {
get("/health") { text("ok") }
get("/ready") { text("ready") }
}
KOTLIN
curl -fsS http://127.0.0.1:8081/health
curl -fsS http://127.0.0.1:8081/ready
Run a complete Kotlin file
Pass an App.kt with its own main function. Arguments after the filename are passed to the compiled app.
./ktserve run App.kt
Add a dependency
Pass --dependency group:artifact:version before App.kt. Repeat the flag for each library. Gradle resolves these dependencies from Maven Central. Each library needs a variant for your Kotlin/Native target.
Save this example as App.kt.
import codes.draeger.ktserve.*
import kotlinx.datetime.LocalDate
fun main() {
serve {
get("/date") { text(LocalDate(2026, 11, 27).toString()) }
}
}
./ktserve run --dependency org.jetbrains.kotlinx:kotlinx-datetime:0.7.1 App.kt
Request the date with curl -fsS http://127.0.0.1:8080/date. Kotlin Multiplatform dependencies
Validate a typed API and generate OpenAPI
Download a complete Kotlin app and opt in to validation and OpenAPI for that run.
curl -fsSLO https://raw.githubusercontent.com/christian-draeger/ktserve/cli-preview-0.1.7/components/ktserve/experiments/cli/run/TypedApp.kt &&
./ktserve run --extension validation --extension openapi --source - < TypedApp.kt
The first request returns JSON with status 201. A one-character name returns 422. The last request reads the generated API contract.
curl -fsS http://127.0.0.1:8080/api/users \
-H 'Content-Type: application/json' -d '{"name":"Ada"}'
curl -isS http://127.0.0.1:8080/api/users \
-H 'Content-Type: application/json' -d '{"name":"A"}'
curl -fsS http://127.0.0.1:8080/openapi.json
Serve a directory or configure HTTPS
Use your own public/ directory or extract the sample archive in an empty directory. The archive command uses the platform selected above.
curl -fsSL https://github.com/christian-draeger/ktserve/releases/download/cli-preview-0.1.7/ktserve-cli-preview-0.1.7-linux-x86_64.tar.gz | tar -xzf -
HTTP
./ktserve serve ./public
curl -fsS http://127.0.0.1:8080/api/status.json
HTTPS on Linux
With an HTTPS download, provide a PEM certificate chain and its matching unencrypted key. Keep the key outside the directory you serve.
Create a one-day localhost certificate
Generate a self-signed certificate for local testing in the extracted directory. The openssl command is available in Ubuntu’s openssl package.
openssl req -x509 -newkey ec \
-pkeyopt ec_paramgen_curve:P-256 \
-noenc -days 1 -subj /CN=localhost \
-addext subjectAltName=DNS:localhost \
-keyout localhost.key -out localhost.pem
PORT=8443 ./ktserve serve ./public \
--tls-cert localhost.pem --tls-key localhost.key
curl -fsS --cacert localhost.pem \
https://localhost:8443/api/status.json
Run this from the extracted directory. --cacert trusts the localhost certificate for this request.
Use --mount /assets ./assets to serve a second directory or --access-log to log requests. Restart the process to refresh the file snapshot.
Build from source
The CLI source includes instructions for building with Kotlin/Native and running a Kotlin file with ktserve run. It also shows how to mount files next to API routes with staticFiles("public").