You can customize the Search API client, for example, by using a custom HTTP client, or by changing the user agent information.

To customize individual requests, for example, with headers or query parameters, see Request options.

Custom HTTP requester

You can create your own client for making HTTP requests when initializing the API client.

1
2
3
4
5
6
// Imports and setup code omitted
final client = SearchClient(
    appId: 'ALGOLIA_APPLICATION_ID',
    apiKey: 'ALGOLIA_API_KEY',
    options: ClientOptions(requester: CustomRequester())
);

Custom user agent

If you want to customize the user agent for your requests, use the agentSegments field of the ClientOptions.

1
2
3
4
5
6
7
8
9
10
11
12
13
import 'package:algoliasearch/algoliasearch.dart';

Future<void> main() async {
  final client = SearchClient(
    appId: 'ALGOLIA_APPLICATION_ID',
    apiKey: 'ALGOLIA_API_KEY',
    options: ClientOptions(
      agentSegments: [
        AgentSegment(value: 'custom dart client', version: 'optional version')
      ]
    )
  );
}

This appends “custom dart client (optional version)” to the user-agent header.

Logging

You can set a custom logger to enable more or less logging output:

1
2
3
4
5
var client = SearchClient(
  appId: 'ALGOLIA_APPLICATION_ID',
  apiKey: 'ALGOLIA_API_KEY',
  options: ClientOptions(logger: print),
);
Did you find this page helpful?