AsNet.Shared.Http 1.2.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package AsNet.Shared.Http --version 1.2.1.1
                    
NuGet\Install-Package AsNet.Shared.Http -Version 1.2.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AsNet.Shared.Http" Version="1.2.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AsNet.Shared.Http" Version="1.2.1.1" />
                    
Directory.Packages.props
<PackageReference Include="AsNet.Shared.Http" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AsNet.Shared.Http --version 1.2.1.1
                    
#r "nuget: AsNet.Shared.Http, 1.2.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AsNet.Shared.Http@1.2.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AsNet.Shared.Http&version=1.2.1.1
                    
Install as a Cake Addin
#tool nuget:?package=AsNet.Shared.Http&version=1.2.1.1
                    
Install as a Cake Tool

AsNet.Shared.Http

A shared, enterprise‑grade HTTP infrastructure library for .NET that simplifies API consumption, supports high‑performance streaming, and provides built‑in OAuth2 / OpenID Connect integration (IdentityServer ready).


Features

  • Generic, strongly‑typed HTTP API client abstraction.
  • Full HTTP verb support: GET, POST, PUT, DELETE.
  • Sync and async APIs.
  • High‑performance streaming using IAsyncEnumerable<T>.
  • Advanced error handling with rich metadata (ApiEx).
  • Built‑in JSON serialization configuration with custom converters.
  • Integration with HttpClientFactory.
  • Centralized configuration via appsettings.json.
  • OAuth2 / OpenID Connect token management (IdentityServer compatible).
  • Pluggable token providers (Strategy pattern).
  • Ready‑to‑use IPStack geolocation service.
  • SQL Server Reporting Services (SSRS) helpers.
  • Multi‑framework support.

Typical Use Cases

  • Enterprise microservices communication
  • High‑performance API consumption
  • Streaming large datasets
  • Accessing secured APIs with OAuth2 / OIDC
  • IP geolocation services
  • SSRS report execution and management
  • Shared HTTP infrastructure libraries

Supported Frameworks

  • .NET Standard 2.1
  • .NET 6
  • .NET 7
  • .NET 8
  • .NET 9 / .NET 10 (forward compatible)

The same API surface and development experience are preserved across all runtimes.


Core Components

HTTP API Services

  • IApiService<T> (for .NET 6+)
  • IApiServiceNetStandard<T> (for .NET Standard 2.1)

Provides:

  • Typed HTTP requests and responses
  • Tuple‑based results (Result, HttpResponseMessage, ApiEx)
  • Byte array downloads
  • GET and DELETE with body support
  • Configurable timeout and JSON serialization

Streaming APIs

Efficient processing of large responses using:

  • IAsyncEnumerable<T>
  • Incremental JSON deserialization
  • ResponseHeadersRead

Available methods:

  • GetAsyncEnumerable
  • PostAsyncEnumerable
  • GetFromJsonAsyncEnumerable (NET 8+)

JSON Serialization

  • Based on System.Text.Json
  • Extended with Dahomey.Json
  • Includes custom converters:
    • TimeSpanJsonConverter

Default configuration supports:

  • Case‑insensitive properties
  • Trailing commas
  • Comments
  • Optimized buffers

Error Handling

HTTP errors are transformed into structured exceptions:

  • HTTP status and response propagation
  • Automatic parsing of validation errors (ModelState)
  • Dynamic error payload extraction
  • Rich diagnostic data via Exception.Data

Security & Authentication

OAuth2 / OpenID Connect

Includes a flexible token service designed for secured APIs and compatible with multiple OAuth2 / OpenID Connect providers.

Supported providers include:

  • Duende IdentityServer
  • IdentityServer4
  • Azure AD / Microsoft Entra ID
  • Keycloak
  • Auth0
  • Custom OAuth2/OpenID Connect providers

The token infrastructure follows a provider-based architecture that enables a single application, microservice or integration process to authenticate against multiple authorization servers simultaneously.

This design is especially useful for:

  • Multi-tenant SaaS solutions
  • Enterprise integrations
  • Customer-specific APIs
  • Third-party secured services
  • Hybrid authentication environments
Supported Grant Types
  • Client Credentials
  • Authorization Code
  • Password
  • On‑Behalf‑Of (OBO)
  • Token Exchange
Key Types
  • ITokenService
  • ITokenProvider
  • IOAuthProviderResolver
  • OAuthProviderResolver
  • TokenService
  • TokenRequestContext
  • OAuthProviderSettings

Built‑in providers:

  • ClientCredentialsTokenProvider
  • AuthorizationCodeTokenProvider

Token providers are selected automatically according to the requested GrantType.

OAuth provider configuration is resolved independently, allowing the same application to work with multiple OAuth servers without code changes.

Provider Resolution

When requesting an access token, provider configuration is resolved using the following precedence order:

  1. ProviderSettings (runtime override)
  2. ProviderName (named provider)
  3. Default provider configuration

This allows the library to support:

  • Static application authentication
  • Multiple configured OAuth providers
  • Customer-specific integrations
  • Runtime configuration loaded from databases
  • Fully dynamic multi-tenant environments

IPStack Integration

Includes a ready‑to‑use IP geolocation service:

  • IPStackService (NET 6+)
  • IPStackServiceNetStandard

Features:

  • IP‑based geolocation lookup
  • Standardized result wrapping
  • Integrated error handling
  • Configuration via HttpSettings

SQL Server Reporting Services (SSRS)

Helpers for SSRS integration:

  • Report execution and export
  • Report catalog navigation
  • Parameter discovery
  • Support for SSRS 2005 and 2010+

Supported export formats:

  • PDF, Excel, Word, XML, CSV, HTML, MHTML, Image

Required Configuration

HTTP Settings

"AsNet": {
  "Http": {
    "HttpSettings": {
      "HandlerLifetime": "00:05:00",
      "Timeout": "00:02:00",
      "DefaultClientName": "AsNetSharedHttp",
      "IPStackURL": "http://api.ipstack.com",
      "IPStackAccessKey": "<your-api-key>"
    }
  }
}

### OAuth Provider Settings

The library supports a default OAuth provider and any number of named
providers.

Example:

```json
{
  "AsNet": {
    "Security": {
      "IdentityServerSettings": {

        "Default": {
          "Address": "https://sso.company.com",
          "ClientId": "default-client",
          "ClientSecret": "secret",
          "Scope": "api"
        },

        "Providers": {

          "AsNet": {
            "Address": "https://sso.company.com",
            "ClientId": "client1",
            "ClientSecret": "secret1",
            "Scope": "api"
          },

          "CustomerA": {
            "Address": "https://auth.customera.com",
            "ClientId": "client2",
            "ClientSecret": "secret2",
            "Scope": "documents"
          },

          "CustomerB": {
            "Address": "https://login.customerb.com",
            "ClientId": "client3",
            "ClientSecret": "secret3",
            "Scope": "files"
          }
        }
      }
    }
  }
}

### Token Request Examples

#### Default Provider

Uses the default configured OAuth provider.

```csharp
var token = await tokenService.GetAccessTokenAsync(
    new TokenRequestContext
    {
        GrantType = TokenGrantType.ClientCredentials
    });
Named Provider

Uses a specific provider defined in configuration.

var token = await tokenService.GetAccessTokenAsync(
    new TokenRequestContext
    {
        GrantType = TokenGrantType.ClientCredentials,
        ProviderName = "CustomerA"
    });
Runtime Provider Override

Uses a dynamically supplied provider configuration.

var token = await tokenService.GetAccessTokenAsync(
    new TokenRequestContext
    {
        GrantType = TokenGrantType.ClientCredentials,

        ProviderSettings = new OAuthProviderSettings
        {
            Address = "https://auth.customer.com",
            ClientId = "customer-client",
            ClientSecret = "secret",
            Scope = "api"
        }
    });

Typical scenarios:

  • Customer-specific API integrations
  • Multi-tenant SaaS platforms
  • OAuth settings stored in databases
  • Dynamic runtime authentication ``

Multi-Provider Integration Scenario

A single application can authenticate against different OAuth providers using the same token infrastructure.

Example:

// Internal AsNet API
var asNetToken = await tokenService.GetAccessTokenAsync(
    new TokenRequestContext
    {
        GrantType = TokenGrantType.ClientCredentials,
        ProviderName = "AsNet"
    });

// Customer API
var customerToken = await tokenService.GetAccessTokenAsync(
    new TokenRequestContext
    {
        GrantType = TokenGrantType.ClientCredentials,
        ProviderName = "CustomerA"
    });

// Third-party API
var externalToken = await tokenService.GetAccessTokenAsync(
    new TokenRequestContext
    {
        GrantType = TokenGrantType.ClientCredentials,
        ProviderName = "CustomerB"
    });

Each provider maintains its own authentication configuration and token cache, allowing secure and efficient communication with multiple protected APIs from within the same process.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on AsNet.Shared.Http:

Package Downloads
AsNet.Shared.Data

Enterprise‑grade multi‑tenant data infrastructure library for .NET that provides secure integration with AsNetSecurity, dynamic connection string resolution per tenant, and generic data access components built on Entity Framework Core.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.1.2 120 9/11/2026
1.2.1.1 262 7/9/2026
1.2.1 160 7/6/2026
1.2.0.4 526 5/6/2026
1.2.0.3 271 4/7/2026
1.2.0.2 168 4/6/2026
1.2.0.1 194 2/8/2026
1.2.0 219 1/13/2026
1.1.2 332 6/30/2025
1.1.1 357 1/6/2025
1.1.0.5 309 12/9/2024
1.1.0.4 315 12/9/2024 1.1.0.4 is deprecated because it has critical bugs.
1.1.0.3 323 11/11/2024
1.1.0.2 361 9/6/2024
1.1.0.1 321 6/20/2024
1.1.0 316 6/9/2024
1.0.7.1 448 9/29/2023
1.0.7 284 9/28/2023
1.0.6.10 290 9/23/2023
1.0.6.8 289 9/23/2023
Loading failed

• Optimized and customized JSON serialization using System.Text.Json and Dahomey.Json.
• Improved overall HTTP client performance.
• Added Dependency Injection (DI) ready services for Web API consumption.
• Introduced TimeSpanJsonConverter to properly support TimeSpan properties with System.Text.Json.
• Multi‑framework support: .NET Standard 2.1, .NET 8.0, .NET 9.0, and .NET 10.0.
• Enhanced async methods to return a Tuple (T, HttpResponseMessage, ApiException) for improved diagnostics.
• Added GET and DELETE methods with BodyRequest support.
• Added GetByteArray and GetByteArrayAsync methods for binary content retrieval.
• Added streaming methods: GetAsyncEnumerable, PostAsyncEnumerable, and GetFromJsonAsyncEnumerable.
• Streaming APIs return IAsyncEnumerable<T>, enabling higher performance and memory‑efficient data processing.