meilisearch / meilisearch/meilisearch-java

How to customize OkHttpClient

Open
#903 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement good first issue help wanted
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.