Функция main

fun main() {
    embeddedServer(
        Netty,
        port = 8080,
        host = "127.0.0.1",
        watchPaths = listOf("classes")
    ) { // this: Application
        main()
    }.start(wait = true)
}

Функция Application.main

fun Application.main() {
    config()
    static()
    rest()
    logRoute()
}

Функция Application.static

fun Application.static() {
    routing { // this: Routing
        static("/static") {
            resources()
        }
        ...
    }
}

Функция Application.static

fun Application.static() {
    routing {
        get("/") {
            call.respondHtml(HttpStatusCode.OK, HTML::index)
        }
        static("/static") {
            resources()
        }
    }
}

Функция HTML.index

fun HTML.index() {
    head {
        title("WebApp")
    }
    body {
        div {
            id = "root"
            +"React will be here!!"
        }
        script(src = "/static/webapp.js") {}
    }
}

Функции Application.config

fun Application.config() {
    install(ContentNegotiation) {
        json()
    }
}

Функции Application.rest

fun Application.rest() {
    routing {
        studentRoutes()
    }
}

Репозиторий

val students: MutableList<Student> = mutableListOf(
    Student("Sheldon", "Cooper"),
    Student("Leonard", "Hofstadter"),
    Student("Howard", "Wolowitz"),
    Student("Penny", "Hofstadter")
)

Api сервера

fun Route.studentRoutes(){
    route(Config.studentsPath){ // this: Route
        get { // this: PipelineContext
            if (students.isEmpty()){
                call.respondText(
                    "No students found", 
                    status = HttpStatusCode.NotFound
                )
            } else {
                call.respond(students)
            }
        }
    }
}