Created
August 15, 2020 21:44
-
-
Save mertcb/0c8c9dcce69509774d2310c8065c4e74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mertcb.sskotlin | |
import com.google.gson.Gson | |
import io.ktor.application.call | |
import io.ktor.http.ContentType | |
import io.ktor.request.receive | |
import io.ktor.response.respondText | |
import io.ktor.routing.* | |
val gson = Gson() | |
val users = arrayListOf("Mert","Steve","Paul") | |
fun Routing.users(){ | |
get("/users"){ | |
call.respondText(gson.toJson(users), ContentType.Application.Json) | |
} | |
} | |
fun Routing.addUser(){ | |
post("/users/add"){ | |
val postVal: User= call.receive<User>() | |
users.add(postVal.name) | |
call.respondText("OK", ContentType.Application.Json) | |
} | |
} | |
fun Routing.greetUser(){ | |
post("/users/greet"){ | |
val postVal: User= call.receive<User>() | |
call.respondText("Hello, ${postVal.name}") | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment