HTTP Client Responses

Estimated reading time: 2 minutes

Receiving the body of a response

By default you can use HttpResponse or String as possible types for typed HttpClient requests. So for example:

val htmlContent = client.get<String>("")
val response = client.get<HttpResponse>("")

If JsonFeature is configured, and the server returns the header Content-Type: application/json, you can also specify a class for deserializing it.

val helloWorld = client.get<HelloWorld>("")

The HttpResponse class

From an HttpResponse, you can get the response content easily:

  • val readChannel: ByteReadChannel = response.content
  • val bytes: ByteArray = response.readBytes()
  • val text: String = response.readText()
  • val readChannel =<ByteReadChannel>()
  • val multiPart =<MultiPartData>()
  • val inputStream =<InputStream>() Remember that InputStream API is synchronous!
  • response.discardRemaining()

You can also get the additional response information such as its status, headers, internal state, etc.:


  • val status: HttpStatusCode = response.status
  • val headers: Headers = response.headers


  • val call: HttpClientCall =
  • val version: HttpProtocolVersion = response.version
  • val requestTime: Date = response.requestTime
  • val responseTime: Date = response.responseTime
  • val executionContext: Job = response.executionContext

Extensions for headers:

  • val contentType: ContentType? = response.contentType()
  • val charset: Charset? = response.charset()
  • val lastModified: Date? = response.lastModified()
  • val etag: String? = response.etag()
  • val expires: Date? = response.expires()
  • val vary: List<String>? = response.vary()
  • val contentLength: Int? = response.contentLength()
  • val setCookie: List<Cookie> = response.setCookie()