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
import { algoliasearch } from "algoliasearch";
const client = algoliasearch("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");
await client.searchSingleIndex(
{
indexName: "ALGOLIA_INDEX_NAME",
searchParams: {
query: "SEARCH_QUERY",
},
},
{
// Add a custom HTTP header to this request
headers: {
"extra-header": "greetings",
},
// Add query parameters to this request
queryParameters: {
queryParam: "value",
},
// Adjust timeouts for this request
timeouts: {
read: 10000,
connect: 10000,
}
},
);
Reference
headers
|
type: Record<string, string>
Additional headers as key-value pairs to send with this request. |
queryParameters
|
type: Record<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. |
timeouts
|
type: Timeouts
Timeouts for this request |
timeouts ➔ Timeouts
connect
|
type: number
default: 1,000 (browser), 2,000 (Node.js)
Maximum number of milliseconds to wait for the connection to be established. |
read
|
type: number
default: 2,000 (browser), 5,000 (Node.js)
Maximum number of milliseconds to wait for a response from the server for read requests. |
write
|
type: number
default: 30,000 (browser and Node.js)
Maximum number of milliseconds to wait for a response from the server for write requests. |