feature: Init empty Project
This commit is contained in:
61
src/Application.kt
Normal file
61
src/Application.kt
Normal 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user