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

To customize individual requests, see Request options.

Logging

You can adjust the log verbosity by creating a custom configuration:

1
2
3
4
5
6
7
8
9
10
@preconcurrency import Search

let config = try SearchClientConfiguration(
    appID: "ALGOLIA_APPLICATION_ID",
    apiKey: "ALGOLIA_API_KEY",
    // Adjust log level (default .info)
    logLevel: .debug
)

let client = try SearchClient(configuration: config)

Timeouts

To change the timeouts for all requests, change the appropriate settings in your API client configuration:

1
2
3
4
5
6
7
8
9
10
11
@preconcurrency import Search

let config = try SearchClientConfiguration(
    appID: "ALGOLIA_APPLICATION_ID",
    apiKey: "ALGOLIA_API_KEY",
    // Adjust timeouts for all requests
    writeTimeout: 60,
    readTimeout: 60,
)

let client = try SearchClient(configuration: config)
readTimeout
type: TimeInterval
default: 5

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

writeTimeout
type: Duration
default: 30

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

Headers

To add headers to all requests, use the defaultHeaders parameter:

1
2
3
4
5
6
7
8
9
10
@preconcurrency import Search

let config = try SearchClientConfiguration(
    appID: "ALGOLIA_APPLICATION_ID",
    apiKey: "ALGOLIA_API_KEY",
    // Add headers to all requests
    defaultHeaders: ["extra-header": "greetings"]
)

let client = try SearchClient(configuration: config)

Custom hosts

If you want to proxy your API requests through another server, use the hosts parameter:

1
2
3
4
5
6
7
8
9
10
11
12
import Core
import Foundation
@preconcurrency import Search

let config = try SearchClientConfiguration(
    appID: "ALGOLIA_APPLICATION_ID",
    apiKey: "ALGOLIA_API_KEY",
    // Use your own servers for proxying requests
    hosts: [.init(url: URL(string: "YOUR_SERVER_URL"))]
}

let client = try SearchClient(configuration: config)
Did you find this page helpful?
Swift API clients v9