VoluntasProgressus.APICore
2.1.9
dotnet add package VoluntasProgressus.APICore --version 2.1.9
NuGet\Install-Package VoluntasProgressus.APICore -Version 2.1.9
<PackageReference Include="VoluntasProgressus.APICore" Version="2.1.9" />
<PackageVersion Include="VoluntasProgressus.APICore" Version="2.1.9" />
<PackageReference Include="VoluntasProgressus.APICore" />
paket add VoluntasProgressus.APICore --version 2.1.9
#r "nuget: VoluntasProgressus.APICore, 2.1.9"
#:package VoluntasProgressus.APICore@2.1.9
#addin nuget:?package=VoluntasProgressus.APICore&version=2.1.9
#tool nuget:?package=VoluntasProgressus.APICore&version=2.1.9
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 viaservices.AddApiCore()
at/health
- Routes or methods can be excluded from wrapping via
[SkipResponseWrapping]
orResponseHandlingSettings:ExcludedPaths
in configuration
Features
- Centralized exception interception via middleware
- Chain of
IExceptionMapper
to map exceptions toErrorResponse
- 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 viaservices.AddApiCore()
unter/health
registriert- Bestimmte Routen oder Methoden können über
[SkipResponseWrapping]
oderResponseHandlingSettings:ExcludedPaths
ausgeschlossen werden
Funktionen
- Zentrale Ausnahmeerfassung über Middleware
IExceptionMapper
-Kette zur Zuordnung von Ausnahmen zuErrorResponse
- 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 | Versions 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. |
-
net9.0
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.9)
- Microsoft.Extensions.Http (>= 9.0.9)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- Fixed bug with html wrapping