Skip to content

Commit 31827ac

Browse files
docs: explain http client customization
1 parent f72c4ad commit 31827ac

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,42 @@ OrbClient client = OrbOkHttpClient.builder()
378378
.build();
379379
```
380380

381+
### Custom HTTP client
382+
383+
The SDK consists of three artifacts:
384+
385+
- `orb-java-core`
386+
- Contains core SDK logic
387+
- Does not depend on [OkHttp](https://square.github.io/okhttp)
388+
- Exposes [`OrbClient`](orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClient.kt), [`OrbClientAsync`](orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientAsync.kt), [`OrbClientImpl`](orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientImpl.kt), and [`OrbClientAsyncImpl`](orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientAsyncImpl.kt), all of which can work with any HTTP client
389+
- `orb-java-client-okhttp`
390+
- Depends on [OkHttp](https://square.github.io/okhttp)
391+
- Exposes [`OrbOkHttpClient`](orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt) and [`OrbOkHttpClientAsync`](orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt), which provide a way to construct [`OrbClientImpl`](orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientImpl.kt) and [`OrbClientAsyncImpl`](orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientAsyncImpl.kt), respectively, using OkHttp
392+
- `orb-java`
393+
- Depends on and exposes the APIs of both `orb-java-core` and `orb-java-client-okhttp`
394+
- Does not have its own logic
395+
396+
This structure allows replacing the SDK's default HTTP client without pulling in unnecessary dependencies.
397+
398+
#### Customized [`OkHttpClient`](https://square.github.io/okhttp/3.x/okhttp/okhttp3/OkHttpClient.html)
399+
400+
> [!TIP]
401+
> Try the available [network options](#network-options) before replacing the default client.
402+
403+
To use a customized `OkHttpClient`:
404+
405+
1. Replace your [`orb-java` dependency](#installation) with `orb-java-core`
406+
2. Copy `orb-java-client-okhttp`'s [`OkHttpClient`](orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OkHttpClient.kt) class into your code and customize it
407+
3. Construct [`OrbClientImpl`](orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientImpl.kt) or [`OrbClientAsyncImpl`](orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientAsyncImpl.kt), similarly to [`OrbOkHttpClient`](orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt) or [`OrbOkHttpClientAsync`](orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt), using your customized client
408+
409+
### Completely custom HTTP client
410+
411+
To use a completely custom HTTP client:
412+
413+
1. Replace your [`orb-java` dependency](#installation) with `orb-java-core`
414+
2. Write a class that implements the [`HttpClient`](orb-java-core/src/main/kotlin/com/withorb/api/core/http/HttpClient.kt) interface
415+
3. Construct [`OrbClientImpl`](orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientImpl.kt) or [`OrbClientAsyncImpl`](orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientAsyncImpl.kt), similarly to [`OrbOkHttpClient`](orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt) or [`OrbOkHttpClientAsync`](orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt), using your new client class
416+
381417
## Undocumented API functionality
382418

383419
The SDK is typed for convenient usage of the documented API. However, it also supports working with undocumented or not yet supported parts of the API.

0 commit comments

Comments
 (0)