VoluntasProgressus.APICore 2.1.9

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

VoluntasProgressus.APICore

Многоязычная документация для пакета API Core – централизованная обработка исключений и стандартизированные API-ответы. Includes full documentation in Russian, English, Deutsch, and 中文.


Русский / Russian

Описание

Этот пакет предоставляет механизм централизованной обработки исключений и формирования стандартизированных API-ответов:

  • Ошибки возвращаются в формате RFC 7807 Problem Details (application/problem+json)
  • Успешные ответы оборачиваются в унифицированный контейнер ApiResponse<T>
  • Контроллер HealthController автоматически регистрируется при вызове services.AddApiCore() и доступен по маршруту /health для проверки состояния сервиса
  • Можно исключать определённые маршруты или методы из обработки через атрибут [SkipResponseWrapping] или конфигурацию ResponseHandlingSettings:ExcludedPaths в appsettings.json

Особенности

  • Централизованное перехватывание исключений через middleware
  • Цепочка IExceptionMapper для сопоставления исключений с ErrorResponse
  • Расширяемый builder ExceptionMapperBuilder
  • Автоматическая упаковка успешных ответов в ApiResponse<T>
  • Поддержка HTTP-статусов и бизнес-ошибок
  • Логирование необработанных исключений
  • Исключение определённых маршрутов из обработки через [SkipResponseWrapping] или ExcludedPaths в настройках
  • Автоматическая регистрация HealthController для мониторинга

Установка

dotnet add package VoluntasProgressus.APICore --version 2.1.9

Настройка через appsettings.json

{
  "ResponseHandling": {
    "ExcludedPaths": [ "/swagger", "/docs" ]
  }
}

Регистрация в DI

// Передаём конфигурацию для настройки ExcludedPaths
services.AddApiCore(Configuration);

// Регистрируем свои ExceptionMapper
services.AddExceptionMappers(builder =>
{
    builder.Add<CustomExceptionMapper>();
});

// Включаем middleware централизованной обработки ошибок
app.UseErrorHandling();

Пример использования атрибута для исключения метода или контроллера

[SkipResponseWrapping]
[ApiController]
[Route("example")]
public class ExampleController : ControllerBase
{
    [HttpGet("ignored")]
    public IActionResult GetIgnored()
    {
        return Ok(new { message = "Этот ответ не будет обёрнут" });
    }
}

English

Description

Provides centralized exception handling and standardized API responses:

  • Errors are returned in RFC 7807 Problem Details format (application/problem+json)
  • Successful responses are wrapped in ApiResponse<T>
  • HealthController is automatically registered via services.AddApiCore() at /health
  • Routes or methods can be excluded from wrapping via [SkipResponseWrapping] or ResponseHandlingSettings:ExcludedPaths in configuration

Features

  • Centralized exception interception via middleware
  • Chain of IExceptionMapper to map exceptions to ErrorResponse
  • Extensible ExceptionMapperBuilder
  • Automatic wrapping of successful responses in ApiResponse<T>
  • Supports HTTP statuses and business exceptions
  • Logging of unhandled exceptions
  • Exclude specific endpoints from wrapping via attribute or configuration
  • Auto-registration of HealthController for health monitoring

Configuration via appsettings.json

{
  "ResponseHandling": {
    "ExcludedPaths": [ "/swagger", "/docs" ]
  }
}

DI Registration

services.AddApiCore(Configuration); // pass IConfiguration for settings

services.AddExceptionMappers(builder =>
{
    builder.Add<CustomExceptionMapper>();
});

app.UseErrorHandling();

Skip wrapping for controller/method

[SkipResponseWrapping]
[ApiController]
[Route("example")]
public class ExampleController : ControllerBase
{
    [HttpGet("ignored")]
    public IActionResult GetIgnored()
    {
        return Ok(new { message = "This response will not be wrapped" });
    }
}

Deutsch / German

Beschreibung

Dieses Paket bietet zentrale Ausnahmebehandlung und standardisierte API-Antworten:

  • Fehler werden im RFC 7807 Problem Details Format zurückgegeben (application/problem+json)
  • Erfolgreiche Antworten werden in ApiResponse<T> verpackt
  • HealthController wird automatisch via services.AddApiCore() unter /health registriert
  • Bestimmte Routen oder Methoden können über [SkipResponseWrapping] oder ResponseHandlingSettings:ExcludedPaths ausgeschlossen werden

Funktionen

  • Zentrale Ausnahmeerfassung über Middleware
  • IExceptionMapper-Kette zur Zuordnung von Ausnahmen zu ErrorResponse
  • Erweiterbarer Builder ExceptionMapperBuilder
  • Automatisches Verpacken erfolgreicher Antworten in ApiResponse<T>
  • Unterstützung von HTTP-Statuscodes und Geschäftslogikfehlern
  • Logging von nicht behandelten Ausnahmen
  • Ausschluss bestimmter Endpunkte über Attribut oder Konfiguration
  • Automatische Registrierung von HealthController für Monitoring

中文 / Chinese

描述

提供集中式异常处理和标准化 API 响应:

  • 错误以 RFC 7807 Problem Details 格式返回 (application/problem+json)
  • 成功响应封装在 ApiResponse<T>
  • HealthController 通过 services.AddApiCore() 自动注册,可通过 /health 检查服务状态
  • 可以通过 [SkipResponseWrapping]ResponseHandlingSettings:ExcludedPaths 配置排除特定路由或方法

功能

  • 通过中间件集中拦截异常
  • IExceptionMapper 链将异常映射为 ErrorResponse
  • 可扩展的 ExceptionMapperBuilder
  • 自动将成功响应包装为 ApiResponse<T>
  • 支持 HTTP 状态码和业务异常
  • 未处理异常日志记录
  • 通过特性或配置排除特定端点
  • 自动注册 HealthController 以便监控服务

License / Лицензия / Lizenz / 许可

MIT License – см. LICENSE.txt

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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

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
2.1.9 52 9/12/2025
2.1.8 52 9/12/2025
2.1.7 56 9/12/2025
2.1.6 54 9/12/2025
2.1.5 56 9/12/2025
2.1.4 56 9/12/2025
2.1.3 61 9/12/2025

- Fixed bug with html wrapping