If you want to change all requests, you can customize the API clients, for example, by changing the user agent information, or changing the default timeouts.

To customize individual requests, see Request options.

Timeouts

To change the timeouts for all requests, edit the client’s configuration.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
require "algolia"

app_id = "ALGOLIA_APPLICATION_ID"
api_key = "ALGOLIA_API_KEY"

client = Algolia::SearchClient.create(
  "ALGOLIA_APPLICATION_ID",
  "ALGOLIA_API_KEY"
)

# Get the configuration object
config = client.api_client.config

# Adjust timeouts
config.read_timeout = 10_000
config.write_timeout = 10_000
config.connect_timeout = 10_000

Reference

connect_timeout
type: Integer
default: 2,000

Maximum number of milliseconds to wait for the connection to be established.

read_timeout
type: Integer
default: 5,000

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

write_timeout
type: Integer
default: 30,000

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

User agent information

The API clients send user agent information as User-Agent header. To append your own information to this parameter, use the add_user_agent_segment function:

1
2
3
4
5
6
7
8
9
require "algolia"

client = Algolia::SearchClient.create(
  "ALGOLIA_APPLICATION_ID",
  "ALGOLIA_API_KEY"
)

# Add information to `User-Agent` header
client.add_user_agent_segment("custom ruby client", "optional version")

This appends “custom ruby client (optional version)” to the User-Agent header.

Headers

To add headers to all requests, use the header_params parameter of the client’s configuration:

1
2
3
4
5
6
7
8
9
10
11
12
require "algolia"

client = Algolia::SearchClient.create(
  "ALGOLIA_APPLICATION_ID",
  "ALGOLIA_API_KEY"
)

# Get the configuration object
config = client.api_client.config

# Add header to all requests
config.header_params["extra-header": "greetings"]
Did you find this page helpful?
Ruby API clients v3