Skip to content

Latest commit

 

History

History
24 lines (15 loc) · 551 Bytes

response-usage.md

File metadata and controls

24 lines (15 loc) · 551 Bytes

Response usage

Kohttp methods return okhttp3.Response which is AutoClosable It's strictly recommended to access it with use to prevent resource leakage.

val response = httpGet { ... }

response.use {
    ...
}

Response body can be retrieved as a JSON, String or InputStream using provided extension functions on Response.

val response = httpGet { ... }

val dataAsJson: JsonNode = response.asJson()

val dataAsString: String? = response.asString()

val dataAsStream: InputStream? = response.asStream()