ktor-examples
Quick and fast rapid development with ktor
HTML + CSS
@Suppress("unused") // Referenced in application.conf
@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
routing {
get("/") {
call.respondText("HELLO WORLD!", contentType = ContentType.Text.Plain)
}
get("/html-dsl") {
call.respondHtml {
head {
link(rel = "stylesheet", href = "/styles.css", type = "text/css")
}
body {
h1 { +"HTML" }
ul {
for (n in 1..10) {
li { +"$n" }
}
}
}
}
}
get("/styles.css") {
call.respondCss {
p {
fontSize = 2.em
}
rule("p.myclass") {
color = Color.blue
}
h1 {
color = Color.darkGray
}
}
}
// Static feature. Try to access `/static/ktor_logo.svg`
static("/static") {
resources("static")
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
VuePress docs
npm i
npm run build
npx serve .vuepress/dist/
1
2
3
2
3
open http://localhost:5000/
Documentation is deployed on GitHub Pages
resources
- Ktor project
- Ktor Getting Started
- Ktor project generator: start.ktor.io
- YouTube: KotlinConf 2018 - Building Server Backends with Ktor by Ryan Harter
- YouTube: Server-Side Development with Ktor by Hadi Hariri - Bengaluru, June 22, 2019
- VuePress
- VuePress partial includes: markdown-it-vuepress-code-snippet-enhanced