AutoWrapper.Core 5.0.0-rc-04

This is a prerelease version of AutoWrapper.Core.
dotnet add package AutoWrapper.Core --version 5.0.0-rc-04
NuGet\Install-Package AutoWrapper.Core -Version 5.0.0-rc-04
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="AutoWrapper.Core" Version="5.0.0-rc-04" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AutoWrapper.Core --version 5.0.0-rc-04
#r "nuget: AutoWrapper.Core, 5.0.0-rc-04"
#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.
// 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 Nuget Nuget downloads .NET Core

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 both Data Annotation and FluentValidation).
  • A configurable API exception.
  • A consistent response format for Result and Errors.
  • A detailed Result response.
  • A detailed Error response.
  • A configurable HTTP StatusCodes and messages.
  • Add Logging support for Request, Response and Exceptions.
  • 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 to UseAutoWrapper. Make sure to update your Startup.cs to use the new name.
  • ProblemDetails is now the default exception format
  • UseApiProblemDetailsException has been renamed to DisableProblemDetailsException
  • Removed Newtonsoft.Json dependency and replaced it with System.Text.Json
  • Use the interface IApiResponse model instead of the concrete ApiResponse model for returning responses using the default format. This allows you to add your own properties that will wrapped within the Result property.
  • AutoWrapIgnore and RequestDataLogIgnore attributes now leaves under AutoWrapper.Attributes namespace. The implementation was changed from using IActionFilter to use Attribute, eliminating all the request header logic.
  • The following options has been removed:
    • ApiVersion
    • ReferenceLoopHandling
    • UseCustomSchema

ReferenceLoopHandling and DefaultContractResolver aren't still supported in .NET 5 that's why handling reference loop and ApiResponse 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

  1. Download and Install the latest AutoWrapper.Core from NuGet or via CLI:
PM> Install-Package AutoWrapper.Core -Version 5.0.0-rc-04
  1. Declare the following namespace within Startup.cs
using AutoWrapper;
  1. Register the middleware below within the Configure() method of Startup.cs "before" the UseRouting() 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

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

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.

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> | BMC |

Thank you!

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 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

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 1,640 7/11/2023
5.0.0-rc-03 14,142 8/25/2021
5.0.0-rc-02 1,465 8/13/2021
5.0.0-rc 1,467 8/4/2021
4.5.1 63,265 7/11/2023
4.5.0 785,816 3/9/2021
4.4.0 18,736 2/4/2021
4.3.2 13,744 1/12/2021
4.3.1 72,308 9/23/2020
4.3.0 19,256 8/3/2020
4.2.2 67,292 6/4/2020
4.2.1 1,874 6/3/2020
4.2.0 2,297 6/2/2020
4.2.0-rc 1,737 5/23/2020
4.1.0 22,145 4/19/2020
4.1.0-rc2 1,816 3/17/2020
4.1.0-rc 1,601 3/16/2020
4.0.1 60,310 3/15/2020
4.0.0 8,222 3/3/2020
4.0.0-rc 1,837 2/26/2020
3.0.0 22,425 2/2/2020
2.1.0 49,027 11/9/2019
2.0.2 2,146 11/6/2019
2.0.1 4,129 10/17/2019
2.0.0-rc2 1,664 10/15/2019
2.0.0-rc 1,626 10/14/2019
1.2.0 1,989 10/7/2019
1.1.0 1,854 10/4/2019
1.0.0 2,987 9/23/2019
1.0.0-rc 689 9/14/2019

See project repo for release notes.