Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codeSnippets/snippets/_misc_client/AndroidConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.net.InetSocketAddress

val client = HttpClient(Android) {
engine {
// this: [[[AndroidEngineConfig|https://api.ktor.io/ktor-client/ktor-client-android/io.ktor.client.engine.android/-android-engine-config/index.html]]]
// this: [[[AndroidEngineConfig|https://api.ktor.io/ktor-client-android/io.ktor.client.engine.android/-android-engine-config/index.html]]]
connectTimeout = 100_000
socketTimeout = 100_000
proxy = Proxy(Proxy.Type.HTTP, InetSocketAddress("localhost", 8080))
Expand Down
2 changes: 1 addition & 1 deletion codeSnippets/snippets/_misc_client/ApacheConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.apache.http.HttpHost

val client = HttpClient(Apache) {
engine {
// this: [[[ApacheEngineConfig|https://api.ktor.io/ktor-client/ktor-client-apache/io.ktor.client.engine.apache/-apache-engine-config/index.html]]]
// this: [[[ApacheEngineConfig|https://api.ktor.io/ktor-client-apache/io.ktor.client.engine.apache/-apache-engine-config/index.html]]]
followRedirects = true
socketTimeout = 10_000
connectTimeout = 10_000
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
HttpClient() {
engine {
// this: [[[HttpClientEngineConfig|https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.engine/-http-client-engine-config/index.html]]]
// this: [[[HttpClientEngineConfig|https://api.ktor.io/ktor-client-core/io.ktor.client.engine/-http-client-engine-config/index.html]]]
threadsCount = 4
pipelining = true
}
Expand Down
6 changes: 3 additions & 3 deletions codeSnippets/snippets/_misc_client/CioConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import io.ktor.network.tls.*

val client = HttpClient(CIO) {
engine {
// this: [[[CIOEngineConfig|https://api.ktor.io/ktor-client/ktor-client-cio/io.ktor.client.engine.cio/-c-i-o-engine-config/index.html]]]
// this: [[[CIOEngineConfig|https://api.ktor.io/ktor-client-cio/io.ktor.client.engine.cio/-c-i-o-engine-config/index.html]]]
maxConnectionsCount = 1000
endpoint {
// this: [[[EndpointConfig|https://api.ktor.io/ktor-client/ktor-client-cio/io.ktor.client.engine.cio/-endpoint-config/index.html]]]
// this: [[[EndpointConfig|https://api.ktor.io/ktor-client-cio/io.ktor.client.engine.cio/-endpoint-config/index.html]]]
maxConnectionsPerRoute = 100
pipelineMaxSize = 20
keepAliveTime = 5000
connectTimeout = 5000
connectAttempts = 5
}
https {
// this: [[[TLSConfigBuilder|https://api.ktor.io/ktor-network/ktor-network-tls/io.ktor.network.tls/-t-l-s-config-builder/index.html]]]
// this: [[[TLSConfigBuilder|https://api.ktor.io/ktor-network-tls/io.ktor.network.tls/-t-l-s-config-builder/index.html]]]
serverName = "api.ktor.io"
cipherSuites = CIOCipherSuites.SupportedSuites
trustManager = myCustomTrustManager
Expand Down
2 changes: 1 addition & 1 deletion codeSnippets/snippets/_misc_client/JavaConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.ktor.client.engine.java.*

val client = HttpClient(Java) {
engine {
// this: [[[JavaHttpConfig|https://api.ktor.io/ktor-client/ktor-client-java/io.ktor.client.engine.java/-java-http-config/index.html]]]
// this: [[[JavaHttpConfig|https://api.ktor.io/ktor-client-java/io.ktor.client.engine.java/-java-http-config/index.html]]]
threadsCount = 8
pipelining = true
proxy = ProxyBuilder.http("http://proxy-server.com/")
Expand Down
2 changes: 1 addition & 1 deletion codeSnippets/snippets/_misc_client/JettyConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.eclipse.jetty.util.ssl.SslContextFactory

val client = HttpClient(Jetty) {
engine {
// this: [[[JettyEngineConfig|https://api.ktor.io/ktor-client/ktor-client-jetty-jakarta/io.ktor.client.engine.jetty.jakarta/-jetty-engine-config/index.html]]]
// this: [[[JettyEngineConfig|https://api.ktor.io/ktor-client-jetty-jakarta/io.ktor.client.engine.jetty.jakarta/-jetty-engine-config/index.html]]]
sslContextFactory = SslContextFactory.Client()
clientCacheSize = 12
}
Expand Down
2 changes: 1 addition & 1 deletion codeSnippets/snippets/_misc_client/OkHttpConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import io.ktor.client.engine.okhttp.*

val client = HttpClient(OkHttp) {
engine {
// this: [[[OkHttpConfig|https://api.ktor.io/ktor-client/ktor-client-okhttp/io.ktor.client.engine.okhttp/-ok-http-config/index.html]]]
// this: [[[OkHttpConfig|https://api.ktor.io/ktor-client-okhttp/io.ktor.client.engine.okhttp/-ok-http-config/index.html]]]
config {
// this: OkHttpClient.Builder
followRedirects(true)
Expand Down
2 changes: 1 addition & 1 deletion topics/FAQ.topic
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@

<chapter title="How to resolve 'NoTransformationFoundException'?" id="no-transformation-found-exception">
<p>
<a href="https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.call/-no-transformation-found-exception/index.html">NoTransformationFoundException</a>
<a href="https://api.ktor.io/ktor-client-core/io.ktor.client.call/-no-transformation-found-exception/index.html">NoTransformationFoundException</a>
represents the inability to find a suitable transformation for the <i>received body</i> from
<b>resulted</b> type to <b>expected</b> by the client type.
</p>
Expand Down
4 changes: 2 additions & 2 deletions topics/client-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The Auth plugin handles authentication and authorization in your client applicat
</link-summary>

Ktor provides
the [Auth](https://api.ktor.io/ktor-client/ktor-client-plugins/ktor-client-auth/io.ktor.client.plugins.auth/-auth)
the [Auth](https://api.ktor.io/ktor-client-auth/io.ktor.client.plugins.auth/-auth)
plugin to handle authentication and authorization in your client application.
Typical usage scenarios include logging in users and gaining access to specific resources.

Expand Down Expand Up @@ -60,7 +60,7 @@ Now you can [configure](#configure_authentication) the required authentication p

### Step 1: Choose an authentication provider {id="choose-provider"}

To use a specific authentication provider ([basic](client-basic-auth.md), [digest](client-digest-auth.md), or [bearer](client-bearer-auth.md)), you need to call the corresponding function inside the `install` block. For example, to use the `basic` authentication, call the [basic](https://api.ktor.io/ktor-client/ktor-client-plugins/ktor-client-auth/io.ktor.client.plugins.auth.providers/basic.html) function:
To use a specific authentication provider ([basic](client-basic-auth.md), [digest](client-digest-auth.md), or [bearer](client-bearer-auth.md)), you need to call the corresponding function inside the `install` block. For example, to use the `basic` authentication, call the [basic](https://api.ktor.io/ktor-client-auth/io.ktor.client.plugins.auth.providers/basic.html) function:

```kotlin
install(Auth) {
Expand Down
4 changes: 2 additions & 2 deletions topics/client-basic-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ The basic authentication flow looks as follows:

To send user credentials in the `Authorization` header using the `Basic` scheme, you need to configure the `basic` authentication provider as follows:

1. Call the [basic](https://api.ktor.io/ktor-client/ktor-client-plugins/ktor-client-auth/io.ktor.client.plugins.auth.providers/basic.html) function inside the `install` block.
2. Provide the required credentials using [BasicAuthCredentials](https://api.ktor.io/ktor-client/ktor-client-plugins/ktor-client-auth/io.ktor.client.plugins.auth.providers/-basic-auth-credentials/index.html) and pass this object to the [credentials](https://api.ktor.io/ktor-client/ktor-client-plugins/ktor-client-auth/io.ktor.client.plugins.auth.providers/-basic-auth-config/credentials.html) function.
1. Call the [basic](https://api.ktor.io/ktor-client-auth/io.ktor.client.plugins.auth.providers/basic.html) function inside the `install` block.
2. Provide the required credentials using [BasicAuthCredentials](https://api.ktor.io/ktor-client-auth/io.ktor.client.plugins.auth.providers/-basic-auth-credentials/index.html) and pass this object to the [credentials](https://api.ktor.io/ktor-client-auth/io.ktor.client.plugins.auth.providers/-basic-auth-config/credentials.html) function.
3. Configure the realm using the `realm` property.

```kotlin
Expand Down
2 changes: 1 addition & 1 deletion topics/client-bom-remover.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ presence of BOM is optional, and it may cause problems when it's read by softwar
that does not know how to handle the BOM.

The Ktor client provides
the [BOMRemover](https://api.ktor.io/ktor-client/ktor-client-plugins/ktor-client-bom-remover/io.ktor.client.plugins.bomremover/index.html)
the [BOMRemover](https://api.ktor.io/ktor-client-bom-remover/io.ktor.client.plugins.bomremover/index.html)
plugin that removes BOM from the response body in the UTF-8, UTF-16 (BE), UTF-16 (LE), UTF-32 (BE) and UTF-32 (LE)
encodings.

Expand Down
6 changes: 3 additions & 3 deletions topics/client-caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
The HttpCache plugin allows you to save previously fetched resources in an in-memory or persistent cache.
</link-summary>

The Ktor client provides the [HttpCache](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.plugins.cache/-http-cache/index.html) plugin that allows you to save previously fetched resources in an in-memory or persistent cache.
The Ktor client provides the [HttpCache](https://api.ktor.io/ktor-client-core/io.ktor.client.plugins.cache/-http-cache/index.html) plugin that allows you to save previously fetched resources in an in-memory or persistent cache.


## Add dependencies {id="add_dependencies"}
Expand All @@ -35,8 +35,8 @@ the client executes only the first request and skips the second one since data i

## Persistent cache {id="persistent_cache"}

Ktor allows you to create a persistent cache by implementing the [CacheStorage](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.plugins.cache.storage/-cache-storage/index.html) interface.
On JVM, you can create a file storage by calling the [FileStorage](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.plugins.cache.storage/-file-storage.html) function.
Ktor allows you to create a persistent cache by implementing the [CacheStorage](https://api.ktor.io/ktor-client-core/io.ktor.client.plugins.cache.storage/-cache-storage/index.html) interface.
On JVM, you can create a file storage by calling the [FileStorage](https://api.ktor.io/ktor-client-core/io.ktor.client.plugins.cache.storage/-file-storage.html) function.

To create a file cache storage, pass the `File` instance to the `FileStorage` function.
Then, pass the created storage to the `publicStorage` or `privateStorage` function depending on
Expand Down
2 changes: 1 addition & 1 deletion topics/client-call-id.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ call ID.
## Configure %plugin_name% {id="configure"}

The %plugin_name% plugin configuration, provided by
the [CallIdConfig](https://api.ktor.io/ktor-client/ktor-client-plugins/ktor-client-call-id/io.ktor.client.plugins.callid/-call-id-config/index.html)
the [CallIdConfig](https://api.ktor.io/ktor-client-call-id/io.ktor.client.plugins.callid/-call-id-config/index.html)
class, allows you to generate a call ID and add
it to the call context.

Expand Down
4 changes: 2 additions & 2 deletions topics/client-content-encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
The ContentEncoding plugin allows you to enable specified compression algorithms (such as 'gzip' and 'deflate') and configure their settings.
</link-summary>

The Ktor client provides the [ContentEncoding](https://api.ktor.io/ktor-client/ktor-client-plugins/ktor-client-encoding/io.ktor.client.plugins.compression/-content-encoding)
The Ktor client provides the [ContentEncoding](https://api.ktor.io/ktor-client-encoding/io.ktor.client.plugins.compression/-content-encoding)
plugin that allows you to enable specified compression algorithms (such as `gzip` and `deflate`) and configure their settings.
This plugin serves three primary purposes:
* Sets the `Accept-Encoding` header with the specified quality value.
Expand Down Expand Up @@ -52,7 +52,7 @@ The [example](https://github.com/ktorio/ktor-documentation/tree/%ktor_version%/c
If required, you can implement the `ContentEncoder` interface to create a custom encoder and pass it to the `customEncoder` function.

## Encode request body {id="encode_request_body"}
To encode the request body, use the `compress()` function inside the [HttpRequestBuilder](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.request/-http-request-builder/index.html) block.
To encode the request body, use the `compress()` function inside the [HttpRequestBuilder](https://api.ktor.io/ktor-client-core/io.ktor.client.request/-http-request-builder/index.html) block.
```kotlin
import io.ktor.client.*
import io.ktor.client.engine.cio.*
Expand Down
4 changes: 2 additions & 2 deletions topics/client-cookies.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The Ktor client allows you to handle cookies manually in the following ways:
* The `cookie` function allows you to append a cookie to a [specific request](client-requests.md#cookies).
* The `setCookie` function enables you to parse the `Set-Cookie` header value received in a [response](client-responses.md#headers).

The [HttpCookies](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.plugins.cookies/-http-cookies/index.html) plugin handles cookies automatically and keeps them between calls in storage.
The [HttpCookies](https://api.ktor.io/ktor-client-core/io.ktor.client.plugins.cookies/-http-cookies/index.html) plugin handles cookies automatically and keeps them between calls in storage.
By default, it uses an in-memory storage, but you can also implement a persistent storage using [CookiesStorage](#custom_storage).

## Add dependencies {id="add_dependencies"}
Expand Down Expand Up @@ -51,7 +51,7 @@ client.cookies("http://0.0.0.0:8080/")

## Custom cookie storage {id="custom_storage"}

If required, you can create a custom cookie storage by implementing the [CookiesStorage](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.plugins.cookies/-cookies-storage/index.html) interface:
If required, you can create a custom cookie storage by implementing the [CookiesStorage](https://api.ktor.io/ktor-client-core/io.ktor.client.plugins.cookies/-cookies-storage/index.html) interface:

```kotlin
val client = HttpClient(CIO) {
Expand Down
6 changes: 3 additions & 3 deletions topics/client-create-and-configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

<link-summary>Learn how to create and configure a Ktor client.</link-summary>

After adding the [client dependencies](client-dependencies.md), you can instantiate the client by creating the [HttpClient](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client/-http-client/index.html) class instance and passing an [engine](client-engines.md) as a parameter:
After adding the [client dependencies](client-dependencies.md), you can instantiate the client by creating the [HttpClient](https://api.ktor.io/ktor-client-core/io.ktor.client/-http-client/index.html) class instance and passing an [engine](client-engines.md) as a parameter:

```kotlin
```
{src="snippets/_misc_client/CioCreate.kt"}

In this example, we use the [CIO](https://api.ktor.io/ktor-client/ktor-client-cio/io.ktor.client.engine.cio/-c-i-o/index.html) engine.
In this example, we use the [CIO](https://api.ktor.io/ktor-client-cio/io.ktor.client.engine.cio/-c-i-o/index.html) engine.
You can also omit an engine:

```kotlin
Expand All @@ -24,7 +24,7 @@ In this case, the client will choose an engine automatically depending on the ar
### Basic configuration {id="basic-config"}

To configure the client, you can pass an additional functional parameter to the client constructor.
The [HttpClientConfig](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client/-http-client-config/index.html) class is a base class for configuring the client.
The [HttpClientConfig](https://api.ktor.io/ktor-client-core/io.ktor.client/-http-client-config/index.html) class is a base class for configuring the client.
For instance, you can enable [response validation](client-response-validation.md) using the `expectSuccess` property:

```kotlin
Expand Down
4 changes: 2 additions & 2 deletions topics/client-create-new-application.topic
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@
]]></code-block>
<p>
In Ktor, a client is represented by the <a
href="https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client/-http-client/index.html">HttpClient</a>
href="https://api.ktor.io/ktor-client-core/io.ktor.client/-http-client/index.html">HttpClient</a>
class.
</p>
</step>
<step>
<p>
Use the <a href="https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.request/get.html"><code>HttpClient.get()</code></a> method to <a href="client-requests.md">make a GET request</a>.
Use the <a href="https://api.ktor.io/ktor-client-core/io.ktor.client.request/get.html"><code>HttpClient.get()</code></a> method to <a href="client-requests.md">make a GET request</a>.
A <a href="client-responses.md">response</a> will be received as a <code>HttpResponse</code> class
object.
</p>
Expand Down
4 changes: 2 additions & 2 deletions topics/client-custom-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Instead, you have access to different stages of [handling requests and responses
In this section, we'll demonstrate how to create and install your first plugin that adds a custom header
to each [request](client-requests.md):

1. To create a plugin, call the [createClientPlugin](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.plugins.api/create-client-plugin.html) function and pass a plugin name as an argument:
1. To create a plugin, call the [createClientPlugin](https://api.ktor.io/ktor-client-core/io.ktor.client.plugins.api/create-client-plugin.html) function and pass a plugin name as an argument:
```kotlin
package com.example.plugins

Expand Down Expand Up @@ -304,7 +304,7 @@ You can find the full example here: [ResponseTime.kt](https://github.com/ktorio/

## Access client configuration {id="client-config"}

You can access your client configuration using the `client` property, which returns the [HttpClient](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client/-http-client/index.html) instance.
You can access your client configuration using the `client` property, which returns the [HttpClient](https://api.ktor.io/ktor-client-core/io.ktor.client/-http-client/index.html) instance.
The example below shows how to get the [proxy address](client-proxy.md) used by the client:

```kotlin
Expand Down
4 changes: 2 additions & 2 deletions topics/client-default-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
The DefaultRequest plugin allows you to configure default parameters for all requests.
</link-summary>

The [DefaultRequest](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.plugins/-default-request/index.html) plugin allows you to configure default parameters for all [requests](client-requests.md): specify a base URL, add headers, configure query parameters, and so on.
The [DefaultRequest](https://api.ktor.io/ktor-client-core/io.ktor.client.plugins/-default-request/index.html) plugin allows you to configure default parameters for all [requests](client-requests.md): specify a base URL, add headers, configure query parameters, and so on.


## Add dependencies {id="add_dependencies"}
Expand Down Expand Up @@ -68,7 +68,7 @@ If you make the following request using the client with the above configuration,
{src="snippets/client-default-request/src/main/kotlin/com/example/Application.kt" include-lines="25"}

... the resulting URL will be the following: `https://ktor.io/docs/welcome.html`.
To learn how base and request URLs are merged, see [DefaultRequest](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.plugins/-default-request/index.html).
To learn how base and request URLs are merged, see [DefaultRequest](https://api.ktor.io/ktor-client-core/io.ktor.client.plugins/-default-request/index.html).


### URL parameters {id="url-params"}
Expand Down
Loading