data class Response : Closeable
(source)
The Response data class represents a reponse to a Request send by a Client.
You can create a Response object using the constructor, but you are more likely to encounter a Response object being returned as the result of calling Client.fetch.
A Response may hold references to other resources (e.g. streams). Therefore it's important to always close the
Response object or its Body. This can be done by either consuming the content of the Body with one of the
available methods or by using Kotlin's extension methods for using Closeable implementations (like use()
):
val response = ...
response.use {
// Use response. Resources will get released automatically at the end of the block.
}
class Body : Closeable, AutoCloseable
|
Response(url: String, status: Int, headers: Headers, body: Body)
The Response data class represents a reponse to a Request send by a Client. |
val body: Body |
|
val headers: Headers |
|
val status: Int |
|
val url: String |
fun close(): Unit
Closes this Response and its Body and releases any system resources associated with it. |
val Response.clientError: Boolean
Returns true if the response was a client error (status in the range 400-499) or false otherwise. |
|
val Response.success: Boolean
Returns true if the response was successful (status in the range 200-299) or false otherwise. |