Skip to content

Instantly share code, notes, and snippets.

@lambrospetrou
Created May 21, 2019 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lambrospetrou/11e268742381c56819ecc5f0c5f712d1 to your computer and use it in GitHub Desktop.
Save lambrospetrou/11e268742381c56819ecc5f0c5f712d1 to your computer and use it in GitHub Desktop.
Kotlin server script
  1. Install tools
curl -s “https://get.sdkman.io" | bash

sdk install kotlin
sdk install kscript
  1. Run the script
kscript kotlin-server-script.kts

Enjoy!

#!/usr/bin/env kscript
@file:MavenRepository("maven-central","http://central.maven.org/maven2/")
@file:DependsOnMaven("io.ktor:ktor-server-netty:1.2.0")
import java.util.*
import io.ktor.http.*
import io.ktor.application.*
import io.ktor.response.*
import io.ktor.routing.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
val server = embeddedServer(Netty, port = 8080) {
routing {
get("/") {
call.respondText("Belloooo!!", ContentType.Text.Plain)
}
get("/minion") {
call.respondText("Belloooo ! I am kevin !")
}
}
}
server.start(wait = true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment