MyNihongo.FluentHttp 1.0.5

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package MyNihongo.FluentHttp --version 1.0.5                
NuGet\Install-Package MyNihongo.FluentHttp -Version 1.0.5                
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="MyNihongo.FluentHttp" Version="1.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MyNihongo.FluentHttp --version 1.0.5                
#r "nuget: MyNihongo.FluentHttp, 1.0.5"                
#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.
// Install MyNihongo.FluentHttp as a Cake Addin
#addin nuget:?package=MyNihongo.FluentHttp&version=1.0.5

// Install MyNihongo.FluentHttp as a Cake Tool
#tool nuget:?package=MyNihongo.FluentHttp&version=1.0.5                

Version Nuget downloads

FluentHttp

Fluent wrapper around IHttpClientFactory
Install a NuGet package MyNihongo.FluentHttp.

Configuration

Add a section to IConfiguration

{
	"FluentHttp": {
		"BaseAddress": "https://jsonplaceholder.typicode.com",
		"NtlmEnabled": false,
		"Timeout": 100
	} 
}
  • Timeout in seconds. for Timeout.Infinite pass -1.

Register a service

using MyNihongo.FluentHttp;

services.AddFluentHttp();

// Or optionally configure the HTTP client
services.AddFluentHttp((services, httpClient) =>
{
	// configure
});

HTTP methods

To optimize JSON serialization JsonTypeInfo<T> can be supplied for all methods. More info about these types here.
In further examples a variable IFluentHttp fluentHttp will be used.

GetJsonAsync

Gets a JSON stream.

[JsonSerializable(typeof(RecordContext[]))]
internal partial class RecordContext : JsonSerializerContext {}

public sealed record RecordContext
{
	public int Id { get; set; }
}

// Get the model
var models = await fluentHttp
	.AppendPathSegment("example")
	.GetJsonAsync(RecordContext.Default.RecordArray, ct);

// When an API may return non-JSON values (e.g. `""`) this method can be used in order to ignore parsing exceptions
fluentHttp.GetJsonOrDefaultAsync(RecordContext.Default.RecordArray, ct);
PostJsonAsync

Posts a JSON model and gets the JSON response.

[JsonSerializable(typeof(Request))]
internal partial class RequestContext : JsonSerializerContext {}

[JsonSerializable(typeof(Response))]
internal partial class ResponseContext : JsonSerializerContext {}

var req = new Request
{
	Data = "example"
};

var response = await fluentHttp
	.AppendPathSegment("example")
	.PostJsonAsync(req, RequestContext.Default.Request, ResponseContext.Default.Response, ct);

// When an API may return non-JSON values (e.g. `""`) this method can be used in order to ignore parsing exceptions
fluentHttp.PostJsonOrDefaultAsync(req, RequestContext.Default.Request, ResponseContext.Default.Response, ct);

Fluent extensions

Fluent extensions supply additional parameters for the main HTTP methods.

AppendPathSegment

Appends a new section to the request URI.

// get from https://jsonplaceholder.typicode.com/posts
var result = await fluentHttp
	.AppendPathSegment("posts")
	.GetJsonAsync<PostRecord>();
AppendPathSegments

Appends multiple sections to the request URI.

// get from https://jsonplaceholder.typicode.com/posts/1/comments
var result = await fluentHttp
	.AppendPathSegment("posts", "1", "comments")
	.GetJsonAsync<PostCommentRecord>();
WithHeader

Appends a header to the request.

var result = await fluentHttp
	.AppendPathSegment("posts")
	.WithHeader("my-header", "value")
	.GetJsonAsync<PostRecord>();
Basic authentication

Append the authentication header for the basic authentication

var result = await fluentHttp
	.AppendPathSegment("posts")
	.WithBasicAuth("username", "strong password")
	.GetJsonAsync<PostRecord>();
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 was computed.  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. 
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
1.1.2 48,059 1/17/2023
1.1.1 62,289 12/26/2022
1.1.0 62,135 12/14/2022
1.0.6 34,671 10/2/2022
1.0.5 17,402 8/11/2022
1.0.4 39,639 3/19/2022
1.0.3 41,790 3/1/2022
1.0.2 2,622 2/26/2022
1.0.1 9,430 1/8/2022