Skip to content

Commit 636ddb8

Browse files
authored
docs: Add howto to override default http client. (#412)
* Add howto to override default http client. * updates from PR feedback * Add badge showing latest version of dependency * remove redundant word
1 parent 970037e commit 636ddb8

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

docs/howto/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ This documentation supplements the official [AWS SDK for Kotlin Developer Guide]
55

66
## Configuration
77

8-
* [Endpoints](./configuring/endpoints.md) - How to configure a custom endpoint resolver
8+
* [Endpoints](./configuring/endpoints.md) - How to configure a custom endpoint resolver
9+
* [Http Clients](./configuring/http-clients.md) - How to specify an alternative HTTP client
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Configuring HTTP Clients
2+
3+
By default the AWS SDK for Kotlin uses an HTTP client known as the AWS Common Runtime (CRT) HTTP client. This
4+
client was written by AWS to ensure the best experience with AWS services. However customers may choose to override
5+
the default HTTP client by specifying an existing [HttpClientEngine](https://github.com/awslabs/smithy-kotlin/blob/main/runtime/protocol/http/common/src/aws/smithy/kotlin/runtime/http/engine/HttpClientEngine.kt)
6+
implementation or implementing their own, and referencing that implementation in the service client configuration at
7+
the time of client construction.
8+
9+
The SDK provides an additional client, `KtorEngine` via the `aws.smithy.kotlin:http-client-engine-ktor` dependency.
10+
11+
[![Maven][maven-badge]][maven-url]
12+
13+
[maven-badge]: https://img.shields.io/maven-central/v/aws.smithy.kotlin/http-client-engine-ktor.svg?label=Maven
14+
[maven-url]: https://search.maven.org/search?q=g:aws.smithy.kotlin+a:http-client-engine-ktor
15+
16+
## Example
17+
18+
The following code snippet demonstrates constructing an S3 client using the [Ktor OkHttp HTTP client](https://ktor.io/docs/http-client-engines.html#okhttp):
19+
20+
`build.gradle.kts`:
21+
```kotlin
22+
dependencies {
23+
implementation("aws.smithy.kotlin:http-client-engine-ktor:<version>")
24+
}
25+
```
26+
27+
Application code:
28+
```kotlin
29+
val sharedConfig = AwsClientConfig.fromEnvironment()
30+
val client = S3Client(sharedConfig) {
31+
httpClientEngine = KtorEngine()
32+
}
33+
```

0 commit comments

Comments
 (0)