Api connector
Overview
Basic support for creating API connectors to API services, especially REST API clients now.
Install
- ASOL.Core.ApiConnector - Base classes to implement own clients in your service and infrastructure implementation for connect to other services.
Changelog
- 0.0.1.48438-dev
- health check for connected application has been changed from readiness to liveness
- 0.0.1.48085-dev
- BREAKING CHANGE: Dependency on ASOL.Core.Serialization.Abstractions of the version 0.0.1.47069-dev
- ASP.NET Core dependency added
- BREAKING CHANGE: Dependency on ASOL.Core.Identity.Abstractions of the version 0.0.1.47819-dev
- Add cookie support for API connectors.
- 0.0.1.44962-dev
- BREAKING CHANGE: Dependency on ASOL.Core.Multitenancy.Abstractions of the version 0.0.1.44943-dev (from this version onwards, this dependency only supports .NET 8)
- 0.0.1.44925-dev
- BREAKING CHANGE: Support for older .NET frameworks has been removed; only .NET 8 is now supported.
Dependency injection
Mandatory dependency injection registration to allow communicate with clients.
/// <summary>
/// Api Clients setup
/// </summary>
/// <param name="services">Service collection</param>
/// <param name="configuration">Configuration</param>
/// <returns>Service collection</returns>
public static IServiceCollection AddApiClients(this IServiceCollection services, IConfiguration configuration)
{
// Mandatory register ApiConnector infrastructure
services.AddApiConnectorInfrastructure();
//TODO: Here you can add connectors for other services.
// example to add MessageProvider service client - NuGet ASOL.MessageProvider.Connector
//services.Configure<MessageProviderClientOptions>(configuration.GetSection(nameof(MessageProviderClientOptions)));
//services.AddScoped<IMessageProviderClient, MessageProviderClient>();
//services.AddScoped<IMessageProviderClientTokenClient, MessageProviderClientTokenClient>();
return services;
}
Implementation
Example of implementation for your project.
using System.Collections.Generic;
using System.Net.Http;
using ASOL.Core.ApiConnector;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
public partial class MyOwnProjectClient : SecuredApiClientBase<MyOwnProjectClientOptions, IConnectorTokenProvider>, IMyOwnProjectClient
{
public MyOwnProjectClient(
IOptions<MyOwnProjectClientOptions> options,
ILogger<MyOwnProjectClient> logger,
IConnectorTokenProvider tokenProvider,
IEnumerable<IRequestHeaderProvider> headerProviders,
IEnumerable<IRequestCookieProvider> cookieProviders,
HttpClient? baseClient = null,
bool manageBaseClient = false)
: this(options.Value, logger, tokenProvider, headerProviders, cookieProviders, baseClient, manageBaseClient)
{
}
public IMyOwnProjectClientForTestItem TestItems => this;
}