HttpClientConfig
A mutable HttpClient configuration used to adjust settings, install plugins and interceptors.
This configuration can be provided as a lambda in the HttpClient constructor or the HttpClient.config builder:
val client = HttpClient { // HttpClientConfig<Engine>()
// Configure engine settings
engine { // HttpClientEngineConfig
threadsCount = 4
pipelining = true
}
// Install and configure plugins
install(ContentNegotiation) {
json()
}
// Configure default request parameters
defaultRequest {
url("https://api.example.com")
header("X-Custom-Header", "value")
}
// Configure client-wide settings
expectSuccess = true
followRedirects = true
}
Configuring HttpClientEngine
If the engine is specified explicitly, engine-specific properties will be available in the engine
block:
val client = HttpClient(CIO) { // HttpClientConfig<CIOEngineConfig>.() -> Unit
engine { // CIOEngineConfig.() -> Unit
// engine specific properties
}
}
Learn more about the client's configuration from Creating and configuring a client.
Properties
Development mode is no longer required all functionality is enabled by default. The property is safe to remove.
Terminates HttpClient.receivePipeline if the status code is not successful (>=300). Learn more from Response validation.
Specifies whether the client redirects to URLs provided in the Location
header. You can disable redirections by setting this property to false
.
Enables body transformations for many common types like String, ByteArray, ByteReadChannel, etc. These transformations are applied to the request and response bodies.
Functions
Default response validation. Check the response status code in range (0..299).
Installs the UserAgent plugin with a browser-like user agent.
Configure client charsets.
Clones this HttpClientConfig by duplicating all the plugins and customInterceptors.
Installs the UserAgent plugin with a CURL user agent.
Set default request parameters. See DefaultRequest
A builder for configuring engine-specific settings in HttpClientEngineConfig, such as dispatcher, thread count, proxy, and more.
Install HttpCallValidator with block configuration.
Installs the plugin from the other client's configuration.
Install ResponseObserver plugin in client.
Installs the WebSockets plugin using the config as configuration.