Authlink.Portal.Client.Http 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Authlink.Portal.Client.Http --version 2.0.0
                    
NuGet\Install-Package Authlink.Portal.Client.Http -Version 2.0.0
                    
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="Authlink.Portal.Client.Http" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Authlink.Portal.Client.Http" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Authlink.Portal.Client.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 Authlink.Portal.Client.Http --version 2.0.0
                    
#r "nuget: Authlink.Portal.Client.Http, 2.0.0"
                    
#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 Authlink.Portal.Client.Http@2.0.0
                    
#: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=Authlink.Portal.Client.Http&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Authlink.Portal.Client.Http&version=2.0.0
                    
Install as a Cake Tool

📦 Package Overview

Authlink.Portal.Client.Http provides a ready-to-use, production-grade implementation of the IPortalClient abstraction defined in Authlink.Portal.Client.Core.


🚀 Install

dotnet add package Authlink.Portal.Client.Http

Or via Package Manager:

PM> Install-Package Authlink.Portal.Client.Http

🆕 What's New in v2.0

Breaking Changes

All methods now return ErrorOr<TResponse> instead of throwing exceptions. This provides:

  • ✅ Type-safe error handling
  • ✅ Comprehensive error information (status codes, response bodies, exception details)
  • ✅ Better control flow without try-catch blocks
  • ✅ Rich metadata for debugging and logging

🛠️ Usage Examples

Setup

builder.Services.AddPortalHttpClient(options =>
{
    options.BaseUrl = "https://portal.authlink.co.za";
});

Basic Usage with Error Handling

public class MyService
{
    private readonly IPortalClient _client;

    public MyService(IPortalClient client)
    {
        _client = client;
    }

    public async Task GetUsersAsync()
    {
        var request = new UsersRequest
        {
            PageNumber = 1,
            PageSize = 10
        };

        var result = await _client.UsersAsync(request);

        if (result.IsError)
        {
            // Handle error
            var error = result.FirstError;
            Console.WriteLine($"Error: {error.Code} - {error.Description}");

            // Access metadata
            if (error.Metadata.TryGetValue("StatusCode", out var statusCode))
            {
                Console.WriteLine($"HTTP Status: {statusCode}");
            }

            if (error.Metadata.TryGetValue("ResponseBody", out var body))
            {
                Console.WriteLine($"Response: {body}");
            }

            return;
        }

        // Success - use the value
        var response = result.Value;
        Console.WriteLine($"Found {response.TotalCount} users");
        foreach (var user in response.Users)
        {
            Console.WriteLine($"- {user.FirstName} {user.LastName}");
        }
    }
}

Pattern Matching

var result = await _client.UserAsync(new UserRequest { UserId = userId });

return result.Match(
    user => Ok(user),
    errors => errors[0].Type switch
    {
        ErrorType.NotFound => NotFound(),
        ErrorType.Unauthorized => Unauthorized(),
        ErrorType.Forbidden => Forbid(),
        _ => Problem(errors[0].Description)
    }
);

Switching on Error Type

var result = await _client.CreateUserAsync(request);

if (result.IsError)
{
    var error = result.FirstError;

    return error.Type switch
    {
        ErrorType.Validation => BadRequest(error.Description),
        ErrorType.Conflict => Conflict(error.Description),
        ErrorType.Unauthorized => Unauthorized(),
        ErrorType.Forbidden => Forbid(),
        _ => StatusCode(500, error.Description)
    };
}

return Ok(result.Value);

🔧 Error Types

The client returns specific error types for common scenarios:

Error Code Error Type HTTP Status Description
Portal.ValidationFailed Validation 400 Request validation failed
Portal.Unauthorized Unauthorized 401 Authentication required
Portal.Forbidden Forbidden 403 Insufficient permissions
Portal.NotFound NotFound 404 Resource not found
Portal.Conflict Conflict 409 Resource conflict
Portal.Timeout Failure 408 Request timed out
Portal.NetworkError Failure - Network/connection error
Portal.DeserializationFailed Failure - JSON deserialization failed
Portal.HttpRequestFailed Failure Any General HTTP failure

📊 Error Metadata

All errors include metadata for detailed diagnostics:

if (result.IsError)
{
    var error = result.FirstError;

    // Available metadata keys:
    // - StatusCode: HTTP status code (int)
    // - StatusCodeName: Status code name (string)
    // - ResponseBody: Raw response content (string)
    // - RequestPath: The path that failed (string)
    // - ExceptionType: Exception type name (string)
    // - ExceptionMessage: Exception message (string)
    // - TypeName: Type that failed to deserialize (string)
}

🔄 Migration from v1.x

Before (v1.x)

try
{
    var response = await _client.UsersAsync(request);
    return Ok(response);
}
catch (HttpRequestException ex)
{
    return StatusCode(500, "Request failed");
}

After (v2.0)

var result = await _client.UsersAsync(request);

if (result.IsError)
{
    var error = result.FirstError;
    // Rich error information available
    return Problem(error.Description);
}

return Ok(result.Value);

📚 Documentation

https://docs.authlink.co.za

📄 License

MIT

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.10.0 33 3/6/2026
2.9.0 86 2/18/2026
2.8.0 89 2/18/2026
2.7.0 107 1/30/2026
2.6.0 93 1/29/2026
2.5.0 99 1/29/2026
2.4.0 92 1/28/2026
2.3.0 105 1/7/2026
2.2.4 91 1/7/2026
2.2.3 99 1/7/2026
2.2.2 297 11/12/2025
2.2.1 245 11/10/2025
2.2.0 245 11/10/2025
2.1.0 206 11/4/2025
2.0.0 218 11/3/2025
1.0.1 201 10/29/2025
1.0.0 175 10/10/2025