FS.AspNetCore.ResponseWrapper 10.0.2

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

FS.AspNetCore.ResponseWrapper

NuGet Version NuGet Downloads GitHub License GitHub Stars

Enterprise-grade API response wrapper for ASP.NET Core - standardize your APIs with zero code changes.

Transform your raw controller responses into rich, metadata-enhanced API responses automatically. Add comprehensive error handling, request tracking, pagination support, and enterprise features without modifying existing code.

🎯 Why Use This?

Problem: Your API returns inconsistent response formats, lacks proper error handling, and provides no request tracking or metadata.

Solution: Add one NuGet package and 2 lines of code - get enterprise-grade API responses automatically.

// Before
public async Task<User> GetUser(int id) => await _userService.GetUserAsync(id);

// After (no code changes needed!)
public async Task<User> GetUser(int id) => await _userService.GetUserAsync(id);

Automatic transformation:

{
  "success": true,
  "data": { "id": 1, "name": "John Doe" },
  "metadata": {
    "requestId": "550e8400-e29b-41d4-a716-446655440000",
    "timestamp": "2025-01-15T10:30:45.123Z",
    "executionTimeMs": 42,
    "path": "/api/users/1",
    "method": "GET"
  }
}

✨ Key Features

  • βœ… Zero Code Changes - Works with existing controllers automatically
  • πŸ”„ Automatic Response Wrapping - Consistent format for all endpoints
  • 🚨 Global Error Handling - 12 built-in exception types with error codes
  • ⏱️ Performance Monitoring - Automatic execution time tracking
  • πŸ“„ Universal Pagination - Works with ANY pagination library (duck typing)
  • 🏷️ Smart Metadata Extraction - StatusCode, Message, and custom metadata
  • πŸ” Request Tracing - Correlation IDs for distributed systems
  • πŸŽ›οΈ Highly Configurable - Control every aspect of wrapping behavior
  • πŸ›‘οΈ Production-Ready - .NET 10.0 support, minimal overhead

πŸ“¦ Quick Start

1. Install Package

dotnet add package FS.AspNetCore.ResponseWrapper

2. Configure (2 lines of code)

// Program.cs
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddResponseWrapper(); // πŸ‘ˆ Line 1

var app = builder.Build();

app.UseMiddleware<GlobalExceptionHandlingMiddleware>(); // πŸ‘ˆ Line 2 (optional but recommended)
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();

app.Run();

3. That's It! πŸŽ‰

Your existing controllers now return wrapped responses automatically:

[ApiController]
[Route("api/[controller]")]
public class UsersController : ControllerBase
{
    [HttpGet("{id}")]
    public async Task<User> GetUser(int id)
    {
        var user = await _userService.GetUserAsync(id);
        if (user == null)
            throw new NotFoundException("User", id);
        return user;
    }
}

Success Response:

{
  "success": true,
  "data": { "id": 1, "name": "John Doe", "email": "john@example.com" },
  "metadata": {
    "requestId": "550e8400-e29b-41d4-a716-446655440000",
    "timestamp": "2025-01-15T10:30:45.123Z",
    "executionTimeMs": 42
  }
}

Error Response:

{
  "success": false,
  "data": null,
  "message": "The requested item could not be found",
  "statusCode": "NOT_FOUND",
  "errors": ["User (123) was not found."],
  "metadata": {
    "requestId": "550e8400-e29b-41d4-a716-446655440000",
    "timestamp": "2025-01-15T10:32:15.456Z"
  }
}

πŸ“š Documentation

Core Package

Enterprise Extensions

🎯 Common Use Cases

Basic API with Error Handling

builder.Services.AddResponseWrapper();
app.UseMiddleware<GlobalExceptionHandlingMiddleware>();

API with Pagination

// Works automatically with ANY pagination library!
[HttpGet]
public async Task<PagedResult<Product>> GetProducts(int page = 1)
    => await _service.GetPagedAsync(page, 20);

API with Custom Status Codes

public class LoginResult : IHasStatusCode, IHasMessage
{
    public string Token { get; set; }
    public string StatusCode { get; set; } = "LOGIN_SUCCESS";
    public string Message { get; set; } = "Welcome back!";
}

Enterprise API with All Features

// Install meta package
dotnet add package FS.AspNetCore.ResponseWrapper.Extensions

// One-line setup
builder.Services.AddResponseWrapperWithPreset(PresetType.Enterprise, "MyAPI");
app.UseResponseWrapperExtensions();

🏒 Enterprise Features

Install the all-in-one enterprise package:

dotnet add package FS.AspNetCore.ResponseWrapper.Extensions

Includes:

  • πŸ“Š OpenAPI Integration - Swashbuckle, NSwag, Scalar with enhanced schemas
  • πŸ“ˆ OpenTelemetry - W3C trace context, distributed tracing, custom metrics
  • ⚑ Caching - Memory, Redis, SQL Server with ETag support
  • πŸ”’ Transformation - Data masking (PII protection), field selection, GDPR compliance
  • 🎨 Presets - 9 pre-configured setups (Minimal, Basic, Standard, Advanced, Enterprise, GDPR, Performance, Development, Production)

Quick Enterprise Setup:

// One line gets you everything
builder.Services.AddResponseWrapperWithPreset(PresetType.Enterprise, "MyAPI");
app.UseResponseWrapperExtensions();

See Enterprise Features Documentation for details.

πŸŽ›οΈ Configuration Example

builder.Services.AddResponseWrapper(options =>
{
    // Enable/disable features
    options.EnableExecutionTimeTracking = true;
    options.EnablePaginationMetadata = true;
    options.EnableCorrelationId = true;

    // Exclude specific endpoints
    options.ExcludedPaths = new[] { "/health", "/metrics" };

    // Customize error messages
}, errorMessages =>
{
    errorMessages.ValidationErrorMessage = "Please check your input";
    errorMessages.NotFoundErrorMessage = "Item not found";
});

🚨 Built-in Exception Types

12 exception types with automatic error code extraction:

  • ValidationException - Input validation errors (400)
  • NotFoundException - Resource not found (404)
  • BusinessException - Business rule violations (400)
  • ConflictException - Resource conflicts (409)
  • UnauthorizedException - Authentication required (401)
  • ForbiddenAccessException - Authorization failed (403)
  • BadRequestException - Invalid requests (400)
  • TimeoutException - Operation timeout (408)
  • TooManyRequestsException - Rate limiting (429)
  • ServiceUnavailableException - Service down (503)
  • CustomHttpStatusException - Any custom status code
  • ApplicationExceptionBase - Base for custom exceptions

All exceptions include automatic error codes for client-side handling.

πŸ“Š Response Structure

{
  "success": true,           // Operation outcome
  "data": { ... },           // Your business data
  "message": "...",          // Optional message
  "statusCode": "...",       // Application status code
  "errors": [...],           // Error messages (if any)
  "metadata": {              // Request metadata
    "requestId": "...",      // Unique request ID
    "timestamp": "...",      // Response timestamp
    "executionTimeMs": 42,   // Execution time
    "correlationId": "...",  // Distributed tracing
    "path": "/api/users",    // Request path
    "method": "GET",         // HTTP method
    "pagination": { ... },   // Pagination info (if applicable)
    "additional": { ... }    // Custom metadata
  }
}

πŸ”§ Requirements

  • .NET 10.0 or later
  • ASP.NET Core Web API project

πŸ“„ License

MIT License - see LICENSE file for details.

🀝 Contributing

Contributions are welcome! Please read our Contributing Guide for details.

🌟 What's Next?

  1. βœ… Install the package
  2. πŸ“– Read the Getting Started Guide
  3. πŸ’‘ Check out Examples
  4. πŸš€ Explore Enterprise Features

Made with ❀️ by Furkan Sarıkaya

Transform your ASP.NET Core APIs with enterprise-grade response wrapping. Install today and elevate your API development!

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

Showing the top 5 NuGet packages that depend on FS.AspNetCore.ResponseWrapper:

Package Downloads
FS.AspNetCore.ResponseWrapper.OpenApi.Swashbuckle

Swashbuckle/OpenAPI extension for FS.AspNetCore.ResponseWrapper. Provides automatic OpenAPI schema generation for wrapped responses. Includes pre-built error response examples (400, 404, 500) and complete metadata schemas. Makes wrapped API responses fully discoverable in Swagger UI.

FS.AspNetCore.ResponseWrapper.OpenApi.Scalar

Scalar API documentation extension for FS.AspNetCore.ResponseWrapper. Provides optimized configuration for Scalar API documentation with wrapped responses. Includes theme and display settings optimized for ResponseWrapper schemas.

FS.AspNetCore.ResponseWrapper.OpenTelemetry

OpenTelemetry and distributed tracing integration for FS.AspNetCore.ResponseWrapper. Provides automatic trace context propagation, activity enrichment, and custom metrics for observability.

FS.AspNetCore.ResponseWrapper.Transformation

Response data transformation and filtering for FS.AspNetCore.ResponseWrapper. Provides field selection, data masking for PII/sensitive data, and custom transformations.

FS.AspNetCore.ResponseWrapper.OpenApi.NSwag

NSwag/OpenAPI extension for FS.AspNetCore.ResponseWrapper. Provides automatic OpenAPI schema generation for wrapped responses. Includes pre-built error response examples (400, 404, 500) and complete metadata schemas. Makes wrapped API responses fully discoverable in NSwag UI.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.2 404 12/27/2025
10.0.1 439 12/16/2025
10.0.0.1 279 12/11/2025
10.0.0 653 11/18/2025
9.2.0 556 7/21/2025
9.1.0 199 7/17/2025
9.0.0 199 6/25/2025

Version 10.0.2: Added extensibility framework for enterprise features. Introduced three new interfaces (IResponseEnricher, IMetadataProvider, IResponseTransformer) that enable extension packages to enhance responses, inject custom metadata, and transform data before wrapping. This backward-compatible update provides foundation for upcoming extension packages including OpenAPI/Swagger integration, OpenTelemetry tracing, HTTP caching, and response transformation capabilities. Zero breaking changes - existing applications continue to work without modifications.