Skip to content

Commit c50c96e

Browse files
committed
SDK-1591 Adding documentation for the new OkHttpClient configuration
1 parent 18eebd9 commit c50c96e

File tree

3 files changed

+134
-0
lines changed

3 files changed

+134
-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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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. Add the `OkHttpClient` dependency to your project. For example, in Maven:
40+
```xml
41+
<dependency>
42+
<groupId>com.squareup.okhttp3</groupId>
43+
<artifactId>okhttp</artifactId>
44+
<version>4.9.1</version> // Use the latest version
45+
</dependency>
46+
```
47+
48+
#### 2. Create an instance of `OkHttpClient` with your configurations. You may use an existing instance or create a new one. For example:
49+
```java
50+
OkHttpClient customClient = new OkHttpClient.Builder()
51+
.connectTimeout(30, TimeUnit.SECONDS)
52+
.readTimeout(30, TimeUnit.SECONDS)
53+
.writeTimeout(30, TimeUnit.SECONDS)
54+
.build();
55+
```
56+
For more information on configuring the `OkHttpClient`, refer to the [OkHttp documentation](https://square.github.io/okhttp/).
57+
58+
#### 3. Pass the `OkHttpClient` instance to the `RapidClient` builder `builderWithHttpClient`
59+
```java
60+
RapidClient rapidClient = RapidClient.builderWithHttpClient()
61+
.key("YOUR_API_KEY")
62+
.secret("YOUR_API_SECRET")
63+
.okHttpClient(customClient)
64+
.build();
65+
```
66+
67+
#### 4. Make API Calls: Use the configured rapidClient to make API calls as usual
68+
```java
69+
GetAvailabilityOperationParams getAvailabilityOperationParams = GetAvailabilityOperationParams.builder()
70+
.checkin("YYYY-MM-DD")
71+
.checkout("YYYY-MM-DD")
72+
.currency("USD")
73+
.language("en_US")
74+
/* ... */
75+
.build();
76+
77+
GetAvailabilityOperation operation = new GetAvailabilityOperation(params);
78+
Response<List<Property>> response = rapidClient.execute(operation);
79+
```

docs/java/quick-start.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,54 @@ 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. Add the OkHttpClient dependency to your project, for example, in Maven:
156+
157+
```xml
158+
<dependency>
159+
<groupId>com.squareup.okhttp3</groupId>
160+
<artifactId>okhttp</artifactId>
161+
<version>4.9.1</version> <!-- Use the latest version -->
162+
</dependency>
163+
```
164+
165+
{% br/ %}
166+
167+
### 2.3.2. Create and configure an OkHttpClient instance
168+
Create an instance of OkHttpClient with your custom configurations:
169+
170+
```java
171+
OkHttpClient customClient = new OkHttpClient.Builder()
172+
.connectTimeout(30, TimeUnit.SECONDS)
173+
.readTimeout(30, TimeUnit.SECONDS)
174+
.writeTimeout(30, TimeUnit.SECONDS)
175+
.build();
176+
```
177+
178+
For more information on configuring the `OkHttpClient`, refer to the [OkHttp documentation](https://square.github.io/okhttp/).
179+
180+
{% br/ %}
181+
182+
### 2.3.3. Pass the OkHttpClient instance to the RapidClient builder
183+
184+
```java
185+
RapidClient rapidClient = RapidClient.builderWithHttpClient()
186+
.key("YOUR_API_KEY")
187+
.secret("YOUR_API_SECRET")
188+
.okHttpClient(customClient)
189+
.build();
190+
```
191+
144192
{% /expandoListItem %}
145193
{% /expandoList %}
146194

0 commit comments

Comments
 (0)