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
import Core
@preconcurrency import Search
let client = try SearchClient(
appID: "ALGOLIA_APPLICATION_ID",
apiKey: "ALGOLIA_API_KEY"
)
let searchResults: SearchResponse<Hit> = try await client.searchSingleIndex(
indexName: "ALGOLIA_INDEX_NAME",
searchParams: SearchSearchParams.searchSearchParamsObject(
SearchSearchParamsObject(query: "SEARCH_QUERY")
),
requestOptions: RequestOptions(
// Add a custom HTTP header to this request
headers: ["extra-header": "greetings" ],
// Add query parameters to this request
queryParameters: ["queryParam": "value"],
// Adjust timeout for this request
readTimeout: 60
)
)
Reference
headers
|
type: [String: String]
Additional headers as key-value pairs to send with this request. |
queryParameters
|
type: [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: TimeInterval
default: 5
Maximum number of seconds to wait for a response from the server (for |
writeTimeout
|
type: TimeInterval
default: 30
Maximum number of seconds to wait for a response from the server (for requests other than |