Customize your API clients to tailor request logging, timeouts, user agent information, headers, and hosts for flexible integrations.
To change the settings for all requests,
you can initialize the API client with a custom configuration.To configure individual requests,
see Request options.
Not all API clients support all customization options.
You can set a custom logger to enable more or less logging output.
Report incorrect code
Copy
using Algolia.Search.Clients;// Install with `dotnet add package Microsoft.Extensions.Logging.Console`using Microsoft.Extensions.Logging;var loggerFactory = LoggerFactory.Create(builder =>{ // Log everything from Algolia in the console, including debug logs builder.AddFilter("Algolia", LogLevel.Debug).AddConsole();});var client = new SearchClient( "ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", loggerFactory,);
The following example shows how to add your own servers.
Report incorrect code
Copy
// ...const options = { hosts: [ { // URL of your server without scheme url: "YOUR_SERVER_URL", // Whether this server can be used for read, write, or both requests accept: "readWrite", // read | write | readWrite // https or http protocol: "https", // Optional, if deviating from the default port // port: "PORT" }, ],};// ...
The following example shows how to use a custom HTTP client to make requests.
Report incorrect code
Copy
using Algolia.Search.Clients;var config = new SearchConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");// CustomRequester must implement `IHTTPRequester`var client = new SearchClient(config, new CustomRequester());
By default, the JVM caches DNS resolutions infinitely.
Since Algolia uses multiple IP addresses for load balancing,
you should reduce the time to live (TTL) of the cache.For example, set the TTL of the cache to 60 seconds: