feature: Init empty Project

This commit is contained in:
2019-07-19 09:52:03 +02:00
commit 8af57b775e
12 changed files with 422 additions and 0 deletions

61
src/Application.kt Normal file
View File

@@ -0,0 +1,61 @@
package fr.dcproject
import io.ktor.application.*
import io.ktor.response.*
import io.ktor.request.*
import io.ktor.routing.*
import io.ktor.http.*
import io.ktor.locations.*
import io.ktor.auth.*
import io.ktor.gson.*
import io.ktor.features.*
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
@Suppress("unused") // Referenced in application.conf
@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
install(Locations) {
}
install(Authentication) {
}
install(ContentNegotiation) {
gson {
}
}
routing {
get("/") {
call.respondText("HELLO WORLD!", contentType = ContentType.Text.Plain)
}
get<MyLocation> {
call.respondText("Location: name=${it.name}, arg1=${it.arg1}, arg2=${it.arg2}")
}
// Register nested routes
get<Type.Edit> {
call.respondText("Inside $it")
}
get<Type.List> {
call.respondText("Inside $it")
}
get("/json/gson") {
call.respond(mapOf("hello" to "world"))
}
}
}
@Location("/location/{name}")
class MyLocation(val name: String, val arg1: Int = 42, val arg2: String = "default")
@Location("/type/{name}") data class Type(val name: String) {
@Location("/edit")
data class Edit(val type: Type)
@Location("/list/{page}")
data class List(val type: Type, val page: Int)
}