Created
July 20, 2021 23:37
-
-
Save markchristopherng/3837372fe1d5a96ea8e8fd7ad5146fac to your computer and use it in GitHub Desktop.
This file contains hidden or 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
fun Application.module() { | |
val jsonParser = Json { | |
ignoreUnknownKeys = true | |
isLenient = true | |
} | |
install(ContentNegotiation) { | |
json(jsonParser) | |
} | |
val client = HttpClient(Apache) { | |
install(JsonFeature) { | |
serializer = KotlinxSerializer(jsonParser) | |
} | |
} | |
routing { | |
post("/greeting") { | |
val greetingRequest = call.receive<GreetingRequest>() | |
val ipAddress = client.get<IpAddress>("https://api.ipify.org?format=json") | |
call.respond(GreetingResponse("Hello ${greetingRequest.firstName} ${greetingRequest.lastName}", ipAddress.ip)) | |
} | |
} | |
} | |
@Serializable | |
class IpAddress(var ip: String) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment