AutoWrapper.Core
5.0.0-rc-04
dotnet add package AutoWrapper.Core --version 5.0.0-rc-04
NuGet\Install-Package AutoWrapper.Core -Version 5.0.0-rc-04
<PackageReference Include="AutoWrapper.Core" Version="5.0.0-rc-04" />
paket add AutoWrapper.Core --version 5.0.0-rc-04
#r "nuget: AutoWrapper.Core, 5.0.0-rc-04"
// Install AutoWrapper.Core as a Cake Addin #addin nuget:?package=AutoWrapper.Core&version=5.0.0-rc-04&prerelease // Install AutoWrapper.Core as a Cake Tool #tool nuget:?package=AutoWrapper.Core&version=5.0.0-rc-04&prerelease
<img align="right" src="/src/AutoWrapper/logo.png" />
AutoWrapper
Language: English | 中文
AutoWrapper
is a simple, yet customizable global HTTP
exception handler and response wrapper for ASP.NET Core APIs. It uses an ASP.NET Core middleware
to intercept incoming HTTP
requests and automatically wraps the responses for you by providing a consistent response format for both successful and error results. The goal is to let you focus on your business code specific requirements and let the wrapper automatically handle the HTTP
response. This can speedup the development time when building your APIs while enforcing own standards for your HTTP
responses.
Main features:
- Exception handling.
- A configurable middleware
options
to configure the wrapper. ModelState
validation error handling (support bothData Annotation
andFluentValidation
).- A configurable
API
exception. - A consistent response format for
Result
andErrors
. - A detailed
Result
response. - A detailed
Error
response. - A configurable
HTTP
StatusCodes
and messages. - Add Logging support for
Request
,Response
andExceptions
. - Add support for Problem Details exception format.
- Add support for ignoring action methods that don't need to be wrapped using
[AutoWrapIgnore]
filter attribute.
Breaking changes
- This release supports .NET 5 and .NET 6
- Middleware has been renamed from
UseApiResponseAndExceptionWrapper
toUseAutoWrapper
. Make sure to update yourStartup.cs
to use the new name. ProblemDetails
is now the default exception formatUseApiProblemDetailsException
has been renamed toDisableProblemDetailsException
- Removed
Newtonsoft.Json
dependency and replaced it withSystem.Text.Json
- Use the interface
IApiResponse
model instead of the concreteApiResponse
model for returning responses using the default format. This allows you to add your own properties that will wrapped within theResult
property. AutoWrapIgnore
andRequestDataLogIgnore
attributes now leaves underAutoWrapper.Attributes
namespace. The implementation was changed from usingIActionFilter
to useAttribute
, eliminating all the request header logic.- The following options has been removed:
- ApiVersion
- ReferenceLoopHandling
- UseCustomSchema
ReferenceLoopHandling
andDefaultContractResolver
aren't still supported in .NET 5 that's why handling reference loop andApiResponse
property mappings will not be supported when targetting .NET 5. .NET Core 3.1 will still use Newtonsoft.Json and it's only supported by AutoWrapper ⇐ v4.5.1
Installation
- Download and Install the latest
AutoWrapper.Core
from NuGet or via CLI:
PM> Install-Package AutoWrapper.Core -Version 5.0.0-rc-04
- Declare the following namespace within
Startup.cs
using AutoWrapper;
- Register the
middleware
below within theConfigure()
method ofStartup.cs
"before" theUseRouting()
middleware
:
app.UseAutoWrapper();
That's simple! Here’s how the response is going to look like for the default ASP.NET Core API template “WeatherForecastController
” API:
{
"message": "GET Request successful.",
"result": [
{
"date": "2019-09-16T23:37:51.5544349-05:00",
"temperatureC": 21,
"temperatureF": 69,
"summary": "Mild"
},
{
"date": "2019-09-17T23:37:51.554466-05:00",
"temperatureC": 28,
"temperatureF": 82,
"summary": "Cool"
},
{
"date": "2019-09-18T23:37:51.554467-05:00",
"temperatureC": 21,
"temperatureF": 69,
"summary": "Sweltering"
},
{
"date": "2019-09-19T23:37:51.5544676-05:00",
"temperatureC": 53,
"temperatureF": 127,
"summary": "Chilly"
},
{
"date": "2019-09-20T23:37:51.5544681-05:00",
"temperatureC": 22,
"temperatureF": 71,
"summary": "Bracing"
}
]
}
ASP.NET Core 3.x
For ASP.NET Core 3.x versions, see the documentation here: AutoWrapper v4.x
Unwrapping the Result from .NET Client
AutoWrapper.Server is simple library that enables you unwrap the Result
property of the AutoWrapper's ApiResponse
object in your C# .NET Client code. The goal is to deserialize the Result
object directly to your matching Model
without having you to create the ApiResponse schema.
For example:
[HttpGet]
public async Task<IEnumerable<PersonDTO>> Get()
{
var client = HttpClientFactory.Create();
var httpResponse = await client.GetAsync("https://localhost:5001/api/v1/people");
IEnumerable<PersonDTO> people = null;
if (httpResponse.IsSuccessStatusCode)
{
var jsonString = await httpResponse.Content.ReadAsStringAsync();
people = Unwrapper.Unwrap<IEnumerable<PersonDTO>>(jsonString);
}
return people;
}
For more information, see: AutoWrapper.Server
Samples
- AutoWrapper: Prettify Your ASP.NET Core APIs with Meaningful Responses
- AutoWrapper: Customizing the Default Response Output
- AutoWrapper Now Supports Problem Details For Your ASP.NET Core APIs
- AutoWrapper.Server: Sample Usage
Feedback and Give a Star! ⭐
I’m pretty sure there are still lots of things to improve in this project. Try it out and let me know your thoughts.
Feel free to submit a ticket if you find bugs or request a new feature. Your valuable feedback is much appreciated to better improve this project. If you find this useful, please give it a star to show your support for this project.
Contributors
- Vincent Maverick Durano - Blog
- Huei Feng - Github Profile
- ITninja04 - Github Profile
- Rahmat Slamet - Github Profile
- abelfiore - Github Profile
Want to contribute? Please read the CONTRIBUTING docs here.
Release History
See: Release Log
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Donate
If you find this project useful — or just feeling generous, consider buying me a beer or a coffee. Cheers! 🍻 ☕ | | | | ------------- |:-------------:| | <a href="https://www.paypal.me/vmsdurano"><img src="https://github.com/proudmonkey/Resources/blob/master/donate_paypal.svg" height="40"></a> | |
Thank you!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. 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. |
-
net5.0
- HelpMate.Core (>= 2.1.0)
-
net6.0
- HelpMate.Core (>= 2.1.0)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on AutoWrapper.Core:
Package | Downloads |
---|---|
MarketingBox.Sdk.Common
Package Description |
|
CodeZero
CodeZero is a set of common implementations to help you implementing Clean Architecture, DDD, CQRS, Specification Patterns and another facilities for new modern web applications is an open-source project written in .NET Core. |
|
Shaesk.Auth
This package add auth controller your project auto. check sample project open github. |
|
Lve.Emall.MemberService.Application
Package Description |
|
Kemen.Utility.Log
Library Log Pusintek |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on AutoWrapper.Core:
Repository | Stars |
---|---|
proudmonkey/ApiBoilerPlate
A simple yet organized project template for building ASP.NET Core APIs in .NET Core 3.1
|
Version | Downloads | Last updated |
---|---|---|
5.0.0-rc-04 | 2,529 | 7/11/2023 |
5.0.0-rc-03 | 17,283 | 8/25/2021 |
5.0.0-rc-02 | 1,501 | 8/13/2021 |
5.0.0-rc | 1,499 | 8/4/2021 |
4.5.1 | 142,495 | 7/11/2023 |
4.5.0 | 959,590 | 3/9/2021 |
4.4.0 | 19,656 | 2/4/2021 |
4.3.2 | 13,958 | 1/12/2021 |
4.3.1 | 76,615 | 9/23/2020 |
4.3.0 | 21,648 | 8/3/2020 |
4.2.2 | 70,317 | 6/4/2020 |
4.2.1 | 1,904 | 6/3/2020 |
4.2.0 | 2,328 | 6/2/2020 |
4.2.0-rc | 1,769 | 5/23/2020 |
4.1.0 | 27,565 | 4/19/2020 |
4.1.0-rc2 | 1,876 | 3/17/2020 |
4.1.0-rc | 1,640 | 3/16/2020 |
4.0.1 | 64,905 | 3/15/2020 |
4.0.0 | 8,288 | 3/3/2020 |
4.0.0-rc | 1,865 | 2/26/2020 |
3.0.0 | 23,963 | 2/2/2020 |
2.1.0 | 50,528 | 11/9/2019 |
2.0.2 | 2,176 | 11/6/2019 |
2.0.1 | 4,167 | 10/17/2019 |
2.0.0-rc2 | 1,707 | 10/15/2019 |
2.0.0-rc | 1,663 | 10/14/2019 |
1.2.0 | 2,021 | 10/7/2019 |
1.1.0 | 1,885 | 10/4/2019 |
1.0.0 | 3,305 | 9/23/2019 |
1.0.0-rc | 752 | 9/14/2019 |
See project repo for release notes.