Table of Contents

Class HttpManagerFactory

Namespace
Cuemon.Extensions.Net.Http
Assembly
Cuemon.Extensions.Net.dll

Provides access to factory methods for creating and configuring HttpManager instances.

public static class HttpManagerFactory
Inheritance
HttpManagerFactory

Examples

The following example shows how to create an HTTP manager using HttpManagerFactory with a custom IHttpClientFactory. It performs a GET request and prints the response content.

using System;
using System.Net.Http;
using System.Threading.Tasks;
using Cuemon.Extensions.Net.Http;

namespace Cuemon.Extensions.Net.Http;

public class HttpManagerFactoryExample
{
    public async Task DemonstrateAsync()
    {
        var clientFactory = new HttpClientFactoryStub();

        var manager = HttpManagerFactory.CreateManager(clientFactory, "github");
        var response = await manager.HttpGetAsync(new Uri("https://api.github.com"));
        Console.WriteLine(await response.Content.ReadAsStringAsync());
    }

    private class HttpClientFactoryStub : IHttpClientFactory
    {
        public HttpClient CreateClient(string name)
        {
            var client = new HttpClient();
            client.DefaultRequestHeaders.UserAgent.ParseAdd("HttpManagerFactoryExample");
            return client;
        }
    }
}

Methods

CreateManager(IHttpClientFactory, string)

Creates and returns an HttpManager from the specified factory.

public static HttpManager CreateManager(IHttpClientFactory factory, string name = null)

Parameters

factory IHttpClientFactory

The IHttpClientFactory that determines the HttpClient to use.

name string

The logical name of the client to create.

Returns

HttpManager

HttpManager.