serras / super-simple-ktor

Super Simple Ktor

Home Page:http://serranofp.com/super-simple-ktor/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Module SuperSimpleKtor

The goal of this library is bring a Ktor server up in no-time, using some good defaults. It is not intended for production applications (just use Ktor then), but it becomes really helpful as an educational tool.

import com.serranofp.ktor.simple.*

fun main() = superSimpleKtor {
    // define routes inside
    get("/hi/{name}") {
        respondText("Hello, ${parameters["name"]}!")
    }
}

Main changes w.r.t. Ktor

  • The Handler object is exposed directly (as receiver) within the route handlers, instead of having to use call to access it.
    • That means that parameters or uri are directly available.
  • The routing in superSimpleKtor is restricted to the most basic options -- just HTTP method + route as string + action.
  • The block in superSimpleKtor gets a ResourceScope in context, so you can manage resources correctly.

Defaults

About

Super Simple Ktor

http://serranofp.com/super-simple-ktor/


Languages

Language:Kotlin 100.0%