Skip to content

Instantly share code, notes, and snippets.

@tberghuis
Created January 26, 2025 21:45
Show Gist options
  • Save tberghuis/6669d3d18ca8b083a98cb6e8295a9136 to your computer and use it in GitHub Desktop.
Save tberghuis/6669d3d18ca8b083a98cb6e8295a9136 to your computer and use it in GitHub Desktop.
ktor server android
ktor-version = "3.0.3"
[libraries]
ktor-server-core = { module = "io.ktor:ktor-server-core-jvm", version.ref = "ktor-version" }
ktor-server-netty = { module = "io.ktor:ktor-server-netty", version.ref = "ktor-version" }
implementation(libs.ktor.server.core)
implementation(libs.ktor.server.netty)
// call from ForegroundService init{}
fun runKtorServer(service: ForegroundService) {
val server = embeddedServer(Netty, port = 8080) {
routing {
get("/") {
call.respondText("Hello World!")
}
}
}
server.start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment