|
1 | 1 | # Configuring HTTP Clients |
2 | 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. |
| 3 | +By default, the AWS SDK for Kotlin uses an HTTP client from OkHttp. Customers may choose to override the default HTTP |
| 4 | +client by specifying an existing |
| 5 | +[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 the |
| 7 | +time of client construction. |
8 | 8 |
|
9 | | -The SDK provides an additional client, `KtorEngine` via the `aws.smithy.kotlin:http-client-engine-ktor` dependency. |
| 9 | +The SDK provides an additional client called `CrtHttpEngine` via the `aws.smithy.kotlin:http-client-engine-crt` |
| 10 | +dependency. This implementation wraps the [AWS CRT](https://docs.aws.amazon.com/sdkref/latest/guide/common-runtime.html) |
| 11 | +which provides high-performance, cross-platform implementations of common SDK features. |
10 | 12 |
|
11 | 13 | [![Maven][maven-badge]][maven-url] |
12 | 14 |
|
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 | +[maven-badge]: https://img.shields.io/maven-central/v/aws.smithy.kotlin/http-client-engine-crt.svg?label=Maven |
| 16 | +[maven-url]: https://search.maven.org/search?q=g:aws.smithy.kotlin+a:http-client-engine-crt |
15 | 17 |
|
16 | 18 | ## Example |
17 | 19 |
|
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): |
| 20 | +The following code snippet demonstrates constructing an S3 client using the CRT HTTP client: |
19 | 21 |
|
20 | 22 | `build.gradle.kts`: |
21 | 23 | ```kotlin |
22 | 24 | dependencies { |
23 | | - implementation("aws.smithy.kotlin:http-client-engine-ktor:<version>") |
| 25 | + implementation("aws.smithy.kotlin:http-client-engine-crt:<version>") |
24 | 26 | } |
25 | 27 | ``` |
26 | 28 |
|
27 | 29 | Application code: |
28 | 30 | ```kotlin |
29 | | -val sharedConfig = AwsClientConfig.fromEnvironment() |
30 | | -val client = S3Client(sharedConfig) { |
31 | | - httpClientEngine = KtorEngine() |
| 31 | +val client = S3Client.fromEnvironment { |
| 32 | + httpClientEngine = CrtHttpEngine() |
32 | 33 | } |
33 | | -``` |
| 34 | +``` |
0 commit comments