Skip to content

Commit c729705

Browse files
authored
SDK-1591 Adding documentation for the new OkHttpClient configuration (#244)
1 parent 18eebd9 commit c729705

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

docs/java/logging.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ Example log messages at the DEBUG level:
157157
17:40:08.510 [OkHttp https://test.ean.com/...] DEBUG com.expediagroup.sdk.core.client.OkHttpEventListener - ExpediaSDK: Sending request headers end for transaction-id: [aff4c00d-6f79-4690-8f60-dd1aaccbfaee]
158158
```
159159

160+
{% messageCard type="info" %}
161+
{% messageCardHeader %}
162+
Note
163+
{% /messageCardHeader %}
164+
The debug level logs mentioned above are only available when using the SDK client with the built-in HTTP client. If you configure the SDK client with a custom HTTP client, you must implement this logging within your HTTP client instance.
165+
{% /messageCard %}
166+
160167
## Traceability
161168

162169
The SDK generates a unique `transaction ID` for every API call, which is useful for troubleshooting issues by tracing requests end-to-end. The transactions IDs are added to the request and response headers, and they are logged in error messages in case of exceptions.

docs/java/okhttpclient.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
intro: Introducing Configurable HTTP Client
3+
shortTitle: Introducing Configurable HTTP Client
4+
title: Introducing Configurable HTTP Client
5+
tags:
6+
- new
7+
---
8+
9+
# Introducing Configurable HTTP Client
10+
11+
## What is a Configurable HTTP Client?
12+
13+
The RAPID SDK is built on top of an OkHttpClient that is not open for you to configure and tune. Lately, we've come to
14+
realize your need to tune and optimize the HTTP client to your needs. So in order to give developers using the RAPID SDK
15+
more control over the underlying HTTP client of the SDK, we're introducing a new builder which you can use to pass your
16+
own HTTP Client for the SDK to use internally.
17+
18+
Using this builder, you can build an HTTP client with you own configurations and pass it to the SDK, or even pass a
19+
client you're already using in your application.
20+
21+
{% messageCard type="info" %}
22+
{% messageCardHeader %}
23+
Note
24+
{% /messageCardHeader %}
25+
This feature is available in the `rapid-sdk` v5.2.0 and later.
26+
{% /messageCard %}
27+
28+
## Why use a Configurable HTTP Client?
29+
30+
A configurable HTTP client will benefit you in the following ways:
31+
32+
- **Optimization:** Fine-tune the client for better performance, such as connection pooling, timeouts, and retries.
33+
- **Integration:** Use an existing HTTP client that is already configured and tested within your application.
34+
35+
## How to configure your HTTP client?
36+
37+
To configure your HTTP client, you need to create an instance of `OkHttpClient` and pass it to the `RapidClient` builder.
38+
39+
#### 1. Create an instance of `OkHttpClient` with your configurations. You may use an existing instance or create a new one. For example:
40+
```java
41+
OkHttpClient customClient = new OkHttpClient.Builder()
42+
.connectTimeout(30, TimeUnit.SECONDS)
43+
.readTimeout(30, TimeUnit.SECONDS)
44+
.writeTimeout(30, TimeUnit.SECONDS)
45+
.build();
46+
```
47+
For more information on configuring the `OkHttpClient`, refer to the [OkHttp documentation](https://square.github.io/okhttp/).
48+
49+
#### 2. Pass the `OkHttpClient` instance to the `RapidClient` builder `builderWithHttpClient`
50+
```java
51+
RapidClient rapidClient = RapidClient.builderWithHttpClient()
52+
.key("YOUR_API_KEY")
53+
.secret("YOUR_API_SECRET")
54+
.okHttpClient(customClient)
55+
.build();
56+
```
57+
58+
#### 3. Make API Calls: Use the configured rapidClient to make API calls as usual
59+
```java
60+
GetAvailabilityOperationParams getAvailabilityOperationParams = GetAvailabilityOperationParams.builder()
61+
.checkin("YYYY-MM-DD")
62+
.checkout("YYYY-MM-DD")
63+
.currency("USD")
64+
.language("en_US")
65+
/* ... */
66+
.build();
67+
68+
GetAvailabilityOperation operation = new GetAvailabilityOperation(params);
69+
Response<List<Property>> response = rapidClient.execute(operation);
70+
```

docs/java/quick-start.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,42 @@ RapidClient rapidClient =
141141
.build();
142142
```
143143

144+
{% /expandoListItem %}
145+
146+
{% expandoListItem %}
147+
{% expandoHeading %}
148+
(Optional) 2.3. Configure OkHttp client
149+
{% /expandoHeading %}
150+
151+
The service client can be configured with a custom `OkHttpClient` instance. This allows you to fine-tune the HTTP client
152+
for better performance, such as connection pooling, timeouts, and concurrency handling.
153+
{% br/ %}
154+
155+
### 2.3.1. Create and configure an OkHttpClient instance
156+
Create an instance of OkHttpClient with your custom configurations:
157+
158+
```java
159+
OkHttpClient customClient = new OkHttpClient.Builder()
160+
.connectTimeout(30, TimeUnit.SECONDS)
161+
.readTimeout(30, TimeUnit.SECONDS)
162+
.writeTimeout(30, TimeUnit.SECONDS)
163+
.build();
164+
```
165+
166+
For more information on configuring the `OkHttpClient`, refer to the [OkHttp documentation](https://square.github.io/okhttp/).
167+
168+
{% br/ %}
169+
170+
### 2.3.2. Pass the OkHttpClient instance to the RapidClient builder
171+
172+
```java
173+
RapidClient rapidClient = RapidClient.builderWithHttpClient()
174+
.key("YOUR_API_KEY")
175+
.secret("YOUR_API_SECRET")
176+
.okHttpClient(customClient)
177+
.build();
178+
```
179+
144180
{% /expandoListItem %}
145181
{% /expandoList %}
146182

0 commit comments

Comments
 (0)