FluentHttp.Json 1.2.2

Suggested Alternatives

ReadableHttp

dotnet add package FluentHttp.Json --version 1.2.2
                    
NuGet\Install-Package FluentHttp.Json -Version 1.2.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="FluentHttp.Json" Version="1.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FluentHttp.Json" Version="1.2.2" />
                    
Directory.Packages.props
<PackageReference Include="FluentHttp.Json" />
                    
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 FluentHttp.Json --version 1.2.2
                    
#r "nuget: FluentHttp.Json, 1.2.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.
#:package FluentHttp.Json@1.2.2
                    
#: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=FluentHttp.Json&version=1.2.2
                    
Install as a Cake Addin
#tool nuget:?package=FluentHttp.Json&version=1.2.2
                    
Install as a Cake Tool

FluentHttp.Json

一个轻量的 HttpClient fluent 封装。JSON 和 Form 调用被拆成独立客户端,创建入口由 FluentHttpClient 负责。

Install

dotnet add package FluentHttp.Json

JSON Client

var jsonClient = FluentHttpClient.CreateJson("https://www.example.com", TimeSpan.FromMinutes(1))
    .AddBearerAuthentication("xx-xxx")
    .AddHeaders(("X-App", "demo"));

var result = await jsonClient.GetAsync<Dictionary<string, object>>("/hello");
var result = await jsonClient.GetAsync<Dictionary<string, object>>(
    url: "/hello",
    query: new
    {
        page = 1,
        size = 20,
        keyword = "demo"
    });
var result = await jsonClient.PostAsync<string>(
    url: "/hello".Query(new { key1 = value1, key2 = value2 }),
    body: new
    {
        Question = "今天天气怎么样"
    });

Query 也支持字典和具名元组:

"/hello".Query(new Dictionary<string, object?>
{
    ["page"] = 1,
    ["tags"] = new[] { "a", "b" }
});

"/hello".Query(("page", 1), ("size", 20));

Form Client

var formClient = FluentHttpClient.CreateForm("https://www.example.com")
    .AddBasicAuthentication("demo", "123456");

var result = await formClient.PostAsync<string>(
    url: "/login",
    body: new
    {
        UserName = "demo",
        Password = "123456"
    });

Streaming JSON

var stream = FluentHttpClient.CreateJson("https://www.example.com", TimeSpan.FromMinutes(1))
    .AddBearerAuthentication("xx-xxx")
    .PostStreamAsync<string>(
        url: "/chat",
        body: bodyArguments,
        streamType: FluentHttpExtensions.EventStream);

await foreach (var message in stream)
{
    Console.WriteLine(message);
}

Streaming Form

var stream = FluentHttpClient.CreateForm("https://www.example.com", TimeSpan.FromMinutes(1))
    .PostStreamAsync<string>(
        url: "/events",
        body: new
        {
            UserName = "demo",
            Token = "xxxxx"
        },
        streamType: FluentHttpExtensions.EventStream);

await foreach (var message in stream)
{
    Console.WriteLine(message);
}
var jsonClient = FluentHttpClient.CreateJsonWithCookie(
    baseUrl: "https://www.example.com",
    timeout: TimeSpan.FromMinutes(1),
    ("session", "xxxxx"));

Compatibility

原有的 FluentHttpClient.Create()ReadJsonAsyncReadFormAsyncReadStreamAsyncGetFromJsonAsyncPostFromJsonAsyncHttpClient 扩展仍然可用。PostAsyncPostFromJsonAsyncPostFromFormAsyncPostStreamAsync 支持只指定响应类型,body 可以直接传匿名类或 Dictionary。新项目建议优先使用 CreateJsonCreateFormQuery

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  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 is compatible.  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.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on FluentHttp.Json:

Package Downloads
FluentHttpFactory

Factory helpers for creating FluentHttp JSON and Form clients from IHttpClientFactory.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.2 155 6/3/2026 1.2.2 is deprecated because it is no longer maintained.
1.2.1 119 6/2/2026
1.2.0 109 5/22/2026
1.0.3 315 5/21/2025
1.0.2 365 12/1/2024
1.0.1 170 11/29/2024
1.0.0 156 11/29/2024