NICWebApi.Extensions.RESTfulResult 1.0.41

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

NICWebApi.Extensions.RESTfulResult

NICWebApi.Extensions.RESTfulResult 是一个独立的 API 返回结果格式化扩展库。它只负责统一成功响应、模型验证失败响应和异常响应的结构,不负责控制器发现、路由生成或 HTTP 谓词推断。

特性

  • 统一响应契约:RESTfulResult<T>
  • 统一错误结构:ErrorDetail
  • 成功、验证失败、异常、非 2xx ObjectResult 自动格式化
  • [NotRESTfulResult] 跳过指定 Controller 或 Action
  • 标准 IOptions<RESTfulResultOptions> 配置
  • 可替换异常映射、结果构造和状态码解析策略
  • Swagger 独立注册,不和运行时格式化强绑定

快速开始

builder.Services
    .AddControllers()
    .AddRESTfulResult(options =>
    {
        options.IncludeExceptionDetails = builder.Environment.IsDevelopment();
    });

Swagger 需要显式注册:

builder.Services.AddSwaggerGen();
builder.Services.AddRESTfulResultSwagger();

响应结构

{
  "statusCode": 200,
  "data": {},
  "succeeded": true,
  "errors": [],
  "timestamp": 1710000000
}

手动包装结果

在 Minimal API、特殊 Controller 或不走全局过滤器的场景,可以使用语义化扩展方法:

using NICWebApi.Extensions.RESTfulResult.Extensions;

var success = data.ToSuccessResult();
var failed = data.ToFailedResult("资源不存在", RESTfulResultErrorCodes.NotFound, 404);
var error = exception.ToErrorResult();

跳过格式化

using NICWebApi.Extensions.RESTfulResult.Attributes;

[NotRESTfulResult]
public IActionResult Download()
{
    return File(bytes, "application/octet-stream");
}

更多内容:

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 is compatible.  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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on NICWebApi.Extensions.RESTfulResult:

Package Downloads
NICWebApi.Extensions.AspNetCore

NICWebApi ASP.NET Core 一键集成扩展包,组合 DynamicAPI、RESTfulResult、JWT、Mapper、DependencyInjection、Http、RemoteRequest、Caching、Idempotency、Schedule、Messaging 和 OperationLogging 的默认注册。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.41 153 7/7/2026