Plinth.HttpApiClient 1.5.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
.NET 6.0
dotnet add package Plinth.HttpApiClient --version 1.5.0
NuGet\Install-Package Plinth.HttpApiClient -Version 1.5.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="Plinth.HttpApiClient" Version="1.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Plinth.HttpApiClient --version 1.5.0
#r "nuget: Plinth.HttpApiClient, 1.5.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Plinth.HttpApiClient as a Cake Addin
#addin nuget:?package=Plinth.HttpApiClient&version=1.5.0

// Install Plinth.HttpApiClient as a Cake Tool
#tool nuget:?package=Plinth.HttpApiClient&version=1.5.0

README

Plinth.HttpApiClient

HTTP Api Client framework built on MS HttpClient

Adds logging and tracing to HttpClient based API clients.

There are two supported approaches to building clients, autogenerated clients and manually built clients.

Auto generating clients with nswag

  • install nodejs at least 12+
  • npm install -g nswag
  • run this command, substituting the link to the swagger spec
	nswag openapi2csclient /runtime:net60 '/input:http://localhost:5000/swagger/v1/swagger.json' \
	    /classname:NSwagClient /namespace:My.Project.Client /output:NSwagClient.cs \
	    /operationGenerationMode:SingleClientFromOperationId /generateClientInterfaces:true \
	    /injectHttpClient:true /disposeHttpClient:false /useBaseUrl:false /generateOptionalParameters:true \
	    '/excludedParameterNames:X-Plinth-Auth'

Documentation for configuration options: https://github.com/RicoSuter/NSwag/wiki/NSwag-Configuration-Document

  • Register the client during Startup
     services.AddHttpApiHandlerClient<INSwagClient, NSwagClient>(
        "NSwagClient",
        configureClient: c =>
        {
            c.BaseAddress = new Uri("http://localhost:5000");
        });

Manually building clients

Build a manual api client by deriving from BaseHttpApiClient and implementing API methods using HttpRequestMessage extensions. Example below:

public class MyClient : BaseHttpApiClient
{
    public MyClient(HttpClient client) : base("MyApi", client)
    {
    }

    public async Task<ModelObject?> GetThing(int parameter)
    {
        return await HttpGet("/api/values/thing")
	        .AddQueryParameter("param", parameter)
	        .ExecuteAsync<ModelObject>();
    }

    public async Task<ModelObject?> CreateThing(ModelObject modelObject)
    {
        return await HttpPost("/api/values/thing")
            .SetJsonBody(modelObject)
            .SetAuthorization("myApiToken")
            .ExecuteAsync<ModelObject>();
    }
Product Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Plinth.HttpApiClient:

Package Downloads
Plinth.HttpApiClient.Polly The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Polly extensions for Plinth.HttpApiClient

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.5.0 103 11/9/2022
1.5.0-b88.7a7c20cd 34 11/9/2022
1.4.7 607 10/20/2022
1.4.6 340 10/17/2022
1.4.5 353 10/1/2022
1.4.4 360 8/16/2022
1.4.3 251 8/2/2022
1.4.2 334 7/19/2022
1.4.2-b80.7fdbfd04 74 7/19/2022
1.4.2-b74.acaf86f5 63 6/15/2022
1.4.1 595 6/13/2022
1.4.0 359 6/6/2022
1.3.8 2,151 4/12/2022
1.3.7 303 3/21/2022
1.3.6 261 3/17/2022
1.3.6-b67.ca5053f3 69 3/16/2022
1.3.6-b66.4a9683e6 64 3/16/2022
1.3.5 305 2/23/2022
1.3.4 495 1/20/2022
1.3.3 359 12/29/2021
1.3.2 356 12/11/2021
1.3.1 247 11/12/2021
1.3.0 253 11/8/2021
1.2.3 1,439 9/22/2021
1.2.2 543 8/20/2021
1.2.1 410 8/5/2021
1.2.0 670 8/1/2021
1.2.0-b37.a54030b9 107 6/24/2021
1.1.6 5,315 3/22/2021
1.1.5 1,153 3/9/2021
1.1.4 2,180 2/27/2021
1.1.3 749 2/17/2021
1.1.2 776 2/12/2021
1.1.1 1,085 2/1/2021
1.1.0 817 12/16/2020
1.1.0-b27.b66c309b 233 11/15/2020
1.0.12 2,319 10/18/2020
1.0.11 818 10/6/2020
1.0.10 882 9/30/2020
1.0.9 972 9/29/2020
1.0.8 1,002 9/26/2020
1.0.7 937 9/19/2020
1.0.6 862 9/3/2020
1.0.5 1,077 9/2/2020
1.0.4 1,224 9/1/2020
1.0.3 856 9/1/2020
1.0.2 841 8/29/2020
1.0.1 867 8/29/2020
1.0.0 868 8/29/2020
1.0.0-b1.c22f563d 199 8/28/2020

net7.0 support and removed netcoreapp3.1