# IHttpClientService

## Overview

The [IHttpClientService](/ai/components/api/services/ihttpclientservice.md) in Wisej.AI is utilized whenever an HTTP request is necessary, such as when interacting with LLM providers, vector databases, web searches, and other external services.

For instance, here's how the `WebSearchServiceBase` class utilizes the `IHttpClientService`:

{% tabs %}
{% tab title="C#" %}

```csharp
public WebSearchServiceBase(string url)
{
    _client = ServiceHelper.GetService<IHttpClientService>();
}

internal virtual IHttpClientService Client
{
    get
    {
        if (!_clientInitialized)
        {
            _clientInitialized = true;

            _client.SetHandler(new HttpClientHandler
            {
                AllowAutoRedirect = true,
#if !NETCOREAPP
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
#else
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate | DecompressionMethods.Brotli
#endif
            });

            var apiKey = GetApiKey();
            if (!String.IsNullOrEmpty(apiKey) && !String.IsNullOrEmpty(this.Authentication))
            {
                _client.AddDefaultHeader(this.Authentication, apiKey);
            }

        }

        return _client;
    }
}
private bool _clientInitialized;
private IHttpClientService _client;

```

{% endtab %}
{% endtabs %}

The sample code above class creates an instance of the service and utilizes the `SetHandler()` method to enable decompression. It also employs the `AddDefaultHeader()` method to configure the authentication method and API key. Extending from `WebSearchServiceBase`, the `BingWebSearchService` class uses the `GetAsync()` method on the service instance to perform its operations.

## Default Implementation

The default implementation of `IHttpClientService` is in [`DefaultHttpClientService`](/ai/components/api/services/ihttpclientservice/wisej.ai.services.defaulthttpclientservice.md) and leverages an instance of `System.Net.Http.HttpClient` to handle HTTP requests.

This service acts as an intermediary between the application code utilizing it and the `HttpClient` instance. This design enables developers to implement their own version of `IHttpClientService`, allowing them to intercept and customize all HTTP interactions as needed.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/ai/components/built-in-services/ihttpclientservice.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
