Skip to content

The WebClientService package provides a robust and flexible web client component designed to be used as a service within .NET Core applications. It leverages the power of 'IHttpClientFactory' to facilitate efficient and scalable interactions with web services.

Notifications You must be signed in to change notification settings

konak/am.kon.packages.services.web-client-service

Repository files navigation

.NET

WebClientService for .NET Core

The WebClientService package provides a robust and flexible web client component designed to be used as a service within .NET Core applications. It leverages the power of 'IHttpClientFactory' to facilitate efficient and scalable interactions with web services. This package supports dependency injection, making it easy to integrate into your existing .NET Core applications.

Key Features:

  • Dependency Injection: Seamlessly integrates with the .NET Core dependency injection framework.
  • HTTP Client Management: Utilizes 'IHttpClientFactory' for robust HTTP client instantiation and management.
  • Result Handling: Comprehensive handling of HTTP response results with detailed status and error information.
  • Extensible Base Classes: Abstract base classes for implementing services that interact with web endpoints, returning various data types including strings and streams.
  • Configurable Requests: Supports various HTTP methods, custom headers, bearer token authentication, and more.

Usage Scenarios:

  • Consuming RESTful APIs
  • Fetching data from web services
  • Handling HTTP responses with rich error information
  • Streaming data from endpoints

Getting Started:

  1. Installation: Install the package via NuGet Package Manager.
dotnet add package WebClientService
  1. Configuration: Configure IHttpClientFactory in your Startup.cs.
public void ConfigureServices(IServiceCollection services)
{
    services.AddHttpClient();
    services.AddScoped<WebClientStringDataService>();
    services.AddScoped<WebClientStreamDataService>();
}
  1. Usage: Inject the service into your controllers or services and start making web requests.
public class MyService
{
    private readonly WebClientStringDataService _webClient;

    public MyService(WebClientStringDataService webClient)
    {
        _webClient = webClient;
    }

    public async Task<string> GetDataAsync(Uri requestUri)
    {
        var result = await _webClient.InvokeRequest(requestUri);
        if (result.Result == RequestInvocationResultTypes.Ok)
        {
            return result.Data;
        }
        else
        {
            // Handle error
            throw new Exception(result.Message);
        }
    }
}

About

The WebClientService package provides a robust and flexible web client component designed to be used as a service within .NET Core applications. It leverages the power of 'IHttpClientFactory' to facilitate efficient and scalable interactions with web services.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages