You can customize the Search API client, for example, by using a custom HTTP client, or by changing the user agent information.

To customize individual requests, for example, with headers or query parameters, see Request options.

Custom HTTP requester

You can create your own client for making HTTP requests when initializing the API client, by creating a class that implements com.algolia.utils.Requester.

1
2
3
4
5
6
7
8
9
10
11
12
// Other imports and setup code omitted
import com.algolia.api.SearchClient;
import com.algolia.config.ClientOptions;

var client = new SearchClient(
    "ALGOLIA_APPLICATION_ID",
    "ALGOLIA_API_KEY",
    ClientOptions
        .builder()
        .setRequester(new MyCustomRequester())
        .build()
)

Custom user agent

If you want to customize the user agent for your requests, use the addAlgoliaAgentSegment method.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Other imports and setup code omitted
import com.algolia.api.SearchClient;
import com.algolia.config.ClientOptions;

var options = ClientOptions
                .builder()
                .addAlgoliaAgentSegment("custom java client", "optional version")
                .build()

var client = new SearchClient(
    "ALGOLIA_APPLICATION_ID",
    "ALGOLIA_API_KEY",
    options
);

This appends “custom java client (optional version)” to the user-agent header.

Logging

You can set a custom logger with the ClientOptions.setLogger() method:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Other imports and setup code omitted
import com.algolia.api.SearchClient;
import com.algolia.config.ClientOptions;

var options = ClientOptions
                .builder()
                .setLogger(message -> System.out.println(message))
                .build();


var client = new SearchClient(
    "ALGOLIA_APPLICATION_ID",
    "ALGOLIA_API_KEY",
    options
);
Did you find this page helpful?
Java API clients v4