Request options
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
26
27
28
29
package org.example
import com.algolia.client.api.SearchClient
import com.algolia.client.model.search.SearchParamsObject
import com.algolia.client.transport.RequestOptions
import kotlin.time.DurationUnit
import kotlin.time.toDuration
suspend fun main() {
val client = SearchClient(
appId = "ALGOLIA_APPLICATION_ID",
apiKey = "ALGOLIA_API_KEY"
)
client.searchSingleIndex(
indexName = "ALGOLIA_INDEX_NAME",
searchParams = SearchParamsObject(
query = "SEARCH_QUERY"
),
request_options = RequestOptions(
// Add a custom HTTP header to this request
headers = mapOf("extra-header" to "greetings"),
// Add query parameters to this request
urlParameters = mapOf("queryParam" to "value"),
// Adjust timeout for this request
readTimeout = 10.toDuration(DurationUnit.SECONDS)
)
)
}
Reference
headers
|
type: Map<String,Any>
Additional headers as key-value pairs to send with this request. |
urlParameters
|
type: Map<String,Any>
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: Duration
default: 5
Maximum number of seconds to wait for a response from the server (for |
writeTimeout
|
type: number
default: 30
Maximum number of seconds to wait for a response from the server (for requests other than |