Skip to content

Instantly share code, notes, and snippets.

@ryu1kn
Last active May 8, 2020 11:07
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 ryu1kn/de4acfd49d30a7bd6b3fe6e824063b2f to your computer and use it in GitHub Desktop.
Save ryu1kn/de4acfd49d30a7bd6b3fe6e824063b2f to your computer and use it in GitHub Desktop.
Kotlin + Vert.x simple web server

Kotlin + Vert.x simple web server

gradle jar
java -jar build/libs/foobar-1.0-SNAPSHOT.jar

Then hit port 8080

curl http://localhost:8080/health
// src/App.kt
import io.vertx.core.Vertx
import io.vertx.ext.web.Router
fun main(args: Array<String>) {
val vertx = Vertx.vertx()
val router = Router.router(vertx)
router.get("/health").handler { ctx -> ctx.response().end("OK") }
vertx.createHttpServer().requestHandler(router).listen(8080)
}
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
}
def vertx_version = "3.9.0"
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
compile "io.vertx:vertx-core:$vertx_version"
compile "io.vertx:vertx-lang-kotlin:$vertx_version"
compile "io.vertx:vertx-web:$vertx_version"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
sourceSets {
main {
kotlin {
srcDirs = ['src']
}
}
}
jar {
manifest {
attributes 'Main-Class': 'AppKt'
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment