Nov 06, 2024
Request options
The API client methods accept additional parameters for adding custom headers or query parameters.
You can set these additional request options with the functions
search.WithHeaderParam
and search.WithQueryParam
:
For example:
Copy
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
package main
import (
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)
func main() {
client, _ := search.NewClient(
"ALGOLIA_APPLICATION_ID",
"ALGOLIA_API_KEY"
)
searchParams := search.SearchParams{
SearchParamsObject: search.
NewEmptySearchParamsObject().
SetQuery("SEARCH_QUERY"),
}
client.SearchSingleIndex(
client.
NewApiSearchSingleIndexRequest("ALGOLIA_INDEX_NAME").
WithSearchParams(&searchParams),
// Add a custom HTTP header to this request
search.WithHeaderParam("extra-header", "greetings"),
// Add query parameters to this request
search.WithQueryParam("queryParam", "value"),
)
}
To change timeouts, or set default headers for all requests, see Customize clients.
Reference
search.WithHeaderParam
|
type: function
signature: func(key string, value string) requestOption
Sets extra header parameters for this request. |
search.WithQueryParam
|
type: function
signature: func(key string, value string) requestOption
Sets extra query parameters for this request. |
Did you find this page helpful?