The API client methods accept additional parameters for adding headers or query parameters, or for changing the default timeouts for individual requests.

To customize all requests, you can customize the client.

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
package com.algolia.example

import scala.concurrent.duration.DurationInt
import scala.concurrent.ExecutionContext.Implicits.global

import algoliasearch.api.SearchClient
import algoliasearch.config.RequestOptions
import algoliasearch.search.SearchParamsObject

@main
def main(): Unit = {
    val client = SearchClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")

    client.searchSingleIndex(
        indexName = "ALGOLIA_INDEX_NAME",
        searchParams = Some(SearchParamsObject(query = Some("SEARCH_QUERY"))),
        requestOptions = Some(RequestOptions(
        // Add a custom HTTP header to this request
        headers = Map("extra-header" -> "greetings"),
        // Add query parameters to this request
        queryParameters = Map("queryParam" -> "value"))),
        // Adjust timeout for this request
        readTimeout = Some(100.seconds)
    )
}

Reference

headers
type: Map[String,String]

Additional headers as key-value pairs to send with this request.

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.

readTimeout
type: Option[Duration]

Maximum number of seconds to wait for a response from the server (for GET requests).

writeTimeout
type: Option[Duration]

Maximum number of seconds to wait for a response from the server (for requests other than GET).

Did you find this page helpful?
Scala API clients v2