You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
val s =Server()
s.get("/") {
// Just print pathprintln(it.path)
0
}
s.get("/user{userId:int}") {
// Get pathprintln(it.path)
// Get any path param that you registeredprintln(it.pathParams["userId"].int +10)
// Iterate over all queriesprintln("Queries:")
for (i in it.queries) {
println(i)
}
// Iterate over all HttpHeadersprintln("HTTP Headers:")
for (i in it.headers) {
println(i)
}
// answer to request// now it sends just like stringreturn@get "Hello, world!"
}
s.get("/base") {
println(it.path)
return@get BaseResponse(
"Oops, bad request",
401,
listOf(HttpHeader("Programming-Language", "Kotlin"))
)
}
s.get("/html") {
println(it.path)
return@get HtmlResponse(
"<h1>Oops! Seems like page that you search is not found</h1>",
404,
listOf(HttpHeader("Programming-Language", "Kotlin"))
)
}
s.get("/json") {
println(it.path)
return@get JsonResponse(
Gson().toJson(listOf(1, 2, 3)),
404,
listOf(HttpHeader("Programming-Language", "Kotlin"))
)
}
s.get("/file") {
println(it.path)
return@get FileResponse(Server::class.java.getResource("/happyx.dll")!!.file)
}
s.start()
The text was updated successfully, but these errors were encountered:
Checklist
Minimal Example (Kotlin)
The text was updated successfully, but these errors were encountered: