meilisearch / meilisearch/meilisearch-java
How to customize OkHttpClient
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 245
- Forks
- 152
- PR merge metrics
- No merged PRs in 30d
Description
Description
Currently, the Config class in the Meilisearch Java SDK initializes a default HttpClient as a final field, with no way to inject a custom OkHttpClient instance. This prevents users from configuring advanced HTTP settings such as custom timeouts, connection pooling, interceptors (e.g., logging, retry logic), or proxy configurations — which are essential for production-grade applications.
Basic example
I would like to be able to pass a pre-configured OkHttpClient to the Config class, like this:
OkHttpClient customClient = new OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.addInterceptor(new LoggingInterceptor())
.retryOnConnectionFailure(true)
.build();
Config config = new Config("http://localhost:7700", "masterKey", customClient);
MeiliSearchClient client = new MeiliSearchClient(config);
Currently, this is not possible because Config only accepts hostUrl and apiKey, and internally creates a fixed HttpClient. Adding a constructor that accepts an OkHttpClient (or HttpClient interface) would enable full control over HTTP behavior.
Other
This change would improve flexibility for enterprise users who need custom HTTP behavior (e.g., TLS config, corporate proxies, monitoring).
The change is backward-compatible — existing code continues to work with the default constructor.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Config class and the MeiliSearchClient construction path described in the issue, then inspect how the default HttpClient is initialized. Verify how constructors and existing client creation are tested before adding custom-client support. Done means callers can provide a configured OkHttpClient while existing hostUrl and apiKey construction still uses the default client.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100