The API client methods accept additional parameters for adding headers or query parameters.

If you want to customize the client itself, see Customize clients.

For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.algolia.example;

import com.algolia.api.SearchClient;
import com.algolia.config.RequestOptions;
import com.algolia.model.search.*;

public class Main {
    public static void main(String[] args) {

        try (var client = new SearchClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")) {
            var requestOptions = new RequestOptions()
                // Add a custom HTTP header to this request
                .addExtraHeader("extra-header", "greetings")
                // Add query parameters to this request
                .addExtraQueryParameters("queryParam", "value");

            var searchParams = new SearchParamsObject().setQuery("SEARCH_QUERY");

            client.searchSingleIndex(
                "ALGOLIA_INDEX_NAME",
                searchParams,
                Hit.class,
                requestOptions
            );
        } catch (Exception e) {
            System.err.println("Some kind of error");
        }
    }
}

Query parameters only apply to methods that accept them, such as GET requests.

Reference

headers
type: Map<String,String>

Additional headers as key-value pairs to send with this request. Use the RequestOptions.addExtraHeader() method to set extra headers.

queryParameters
type: Map<String,String>

Additional query parameters to send with this request. They only take effect with API operations that support query parameters. Otherwise, they’re ignored. Use the RequestOptions.addExtraQueryParameters() method to set extra query parameters.

Did you find this page helpful?
Java API clients v4