ZSGF.Client 1.0.17

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

ZSGF.Client

NuGet Version

安装

导航到你的项目目录后,运行以下命令来安装 ZSGF.Client 包:

dotnet add package ZSGF.Client

使用方式

using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using ZSGF.Client.Api;
using ZSGF.Client.Client;
using ZSGF.Client.Model;

namespace YourProject
{
    public class Program
    {
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();
            var api = host.Services.GetRequiredService<IAccessTokenApi>();
            AccessTokenDeleteApiResponse apiResponse = await api.AccessTokenDeleteAsync("todo");
            JObjectApiResult model = apiResponse.Ok();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args)
          .ConfigureApi((context, options) =>
          {
              // 此处令牌的类型取决于 API 安全规范
              ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Authorization);
              options.AddTokens(token);

             // 可选择提供令牌的方法,默认为 RateLimitProvider
              options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();

              options.ConfigureJsonOptions((jsonOptions) =>
              {
                  // 如果有的话,添加任何自定义转换器
              });

              options.AddApiHttpClients(builder: builder => builder
                .AddRetryPolicy(2)
                .AddTimeoutPolicy(TimeSpan.FromSeconds(5))
                .AddCircuitBreakerPolicy(10, TimeSpan.FromSeconds(30))
                // 添加你喜欢的任何中间件
              );
          });
    }
}

问题

  1. HttpRequest 失败和重试机制是怎样的?

如果启用了 supportsRetry,可以在 ConfigureClients 方法中配置 Polly(一种用于处理瞬态故障的库)。

  1. 令牌是如何使用的?

令牌由 TokenProvider 类提供。默认情况下使用的是 RateLimitProvider,它将执行客户端速率限制。也可以使用 UseProvider 方法使用其他提供程序。

  1. 当服务器响应状态不是 Ok 时,HttpRequest 会抛出错误吗?

这取决于你发起请求的方式。如果返回类型是 ApiResponse,不会抛出错误,不过 Content 属性将为 null。StatusCode 和 ReasonPhrase 属性将包含有关错误的信息。如果返回类型是 T,则会抛出错误。如果返回类型是 TOrDefault,则会返回 null。

  1. 如何验证请求和处理响应?

使用 ZSGF.Client.Rest.DefaultApi 命名空间中 Api 类提供的 On 和 After 方法。或者通过使用泛型 ConfigureApi 方法提供你自己的类。

依赖

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  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. 
.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.0.17 107 5 days ago