MyNihongo.FluentHttp 1.1.2

Prefix Reserved
dotnet add package MyNihongo.FluentHttp --version 1.1.2                
NuGet\Install-Package MyNihongo.FluentHttp -Version 1.1.2                
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.1.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MyNihongo.FluentHttp --version 1.1.2                
#r "nuget: MyNihongo.FluentHttp, 1.1.2"                
#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.1.2

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

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>();
AppendParameter

Appends a URL parameter

// get from https://jsonplaceholder.typicode.com/posts?value=123
var result = await fluentHttp
	.AppendPathSegment("posts")
	.AppendParameter("value", "123")
	.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 net5.0 was computed.  net5.0-windows was computed.  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. 
.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

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 50,082 1/17/2023
1.1.1 64,316 12/26/2022
1.1.0 64,160 12/14/2022
1.0.6 36,688 10/2/2022
1.0.5 17,403 8/11/2022
1.0.4 39,640 3/19/2022
1.0.3 41,791 3/1/2022
1.0.2 2,625 2/26/2022
1.0.1 9,431 1/8/2022