Влад Жигульский
Профи
(927)
4 месяца назад
import kotlinx.coroutines.runBlocking
import io.ktor.client.HttpClient
import io.ktor.client.engine.cio.CIO
import io.ktor.client.request.get
const val BASE_URL = "http://kotlin-book.bignerdranch.com/2e"
const val FLIGHT_ENDPOINT = "$BASE_URL/flight"
fun main() {
println("Started")
runBlocking {
val flight = fetchFlight()
println(flight)
}
println("Finished")
}
suspend fun fetchFlight(): String {
val client = HttpClient(CIO)
return client.get(FLIGHT_ENDPOINT).bodyAsText()
}