MyNihongo.FluentHttp
1.0.1
Prefix Reserved
See the version list below for details.
dotnet add package MyNihongo.FluentHttp --version 1.0.1
NuGet\Install-Package MyNihongo.FluentHttp -Version 1.0.1
<PackageReference Include="MyNihongo.FluentHttp" Version="1.0.1" />
paket add MyNihongo.FluentHttp --version 1.0.1
#r "nuget: MyNihongo.FluentHttp, 1.0.1"
// Install MyNihongo.FluentHttp as a Cake Addin #addin nuget:?package=MyNihongo.FluentHttp&version=1.0.1 // Install MyNihongo.FluentHttp as a Cake Tool #tool nuget:?package=MyNihongo.FluentHttp&version=1.0.1
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
}
}
Register a service
using MyNihongo.FluentHttp;
services.AddFluentHttp();
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);
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);
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>();
Product | Versions 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. |
-
net6.0
- Microsoft.Extensions.Configuration.Abstractions (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Http (>= 6.0.0)
- Microsoft.Extensions.ObjectPool (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.