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"]}!")
}
}
- The
Handler
object is exposed directly (as receiver) within the route handlers, instead of having to usecall
to access it.- That means that
parameters
oruri
are directly available.
- That means that
- The routing in
superSimpleKtor
is restricted to the most basic options -- just HTTP method + route as string + action. - The block in
superSimpleKtor
gets aResourceScope
in context, so you can manage resources correctly.
- The whole application runs within a
SuspendApp
context. - Content Negotiation is configured with JSON.
DoubleReceive
andAutoHeadResponse
plug-ins are applied.