QNE.Api.Common 1.0.9

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

QNE.Api.Common

A shared NuGet package providing common API response classes and controller extensions for ASP.NET Core API projects.

Features

  • Standardized API Response Models: Consistent response structure across all API endpoints
  • Controller Extensions: Helpful extension methods for common controller operations
  • Type-Safe Responses: Generic response classes for strongly-typed API responses

Installation

dotnet add package QNE.Api.Common

Or via NuGet Package Manager:

Install-Package QNE.Api.Common

Usage

API Response Classes

Basic Response
using QNE.Api.Common.ApiResponse;

// Generic response with typed data
var response = new ApiResponse<User>
{
    Code = "0000",
    Message = "User retrieved successfully",
    Data = user
};

// Non-generic response
var messageResponse = new ApiResponseMessage
{
    Code = "0000",
    Message = "Operation completed successfully",
    Data = result
};
Response Base Class
public abstract class ApiResponseBase
{
    public string Type { get; set; } = "API";
    public bool Success => Code == "0000";
    public string Code { get; set; } = "0000";
    public string Message { get; set; } = "Operation completed successfully.";
    public object? Error { get; set; }
    public int StatusCode { get; set; } = 200;
}

Controller Extensions

Success Response
using QNE.Api.Common.ControllerExtensions;

[ApiController]
[Route("api/[controller]")]
public class UsersController : ControllerBase
{
    [HttpGet("{id}")]
    public IActionResult GetUser(int id)
    {
        var user = _userService.GetUser(id);
        if (user == null)
            return this.NotExists("User not found");
        
        return this.Success("User retrieved successfully", user);
    }
}
Error Responses
// Permission denied
return this.Denied("You don't have permission to access this resource");

// Not found
return this.NotExists("User does not exist");

// Duplicate entry
return this.Duplicate("User with this email already exists");

// Object in use
return this.InUse("User is currently assigned to a project");

// Custom error
return this.Error("CUSTOM_ERROR_CODE", "Custom error message", additionalData);

// Model validation errors
if (!ModelState.IsValid)
    return this.ModelError();
Identity Errors
var result = await _userManager.CreateAsync(user, password);
if (!result.Succeeded)
    return this.IdentityError(result, "Failed to create user");

Available Extension Methods

  • Success(message?, data?) - Returns a success response
  • Error(code, message, data?) - Returns an error response
  • Denied(message?) - Returns a permission denied response
  • NotExists(message?) - Returns a not found response
  • Duplicate(message) - Returns a duplicate entry error
  • LimitedEntry(type) - Returns a transaction limit exceeded error
  • InUse(message?, data?) - Returns an object in use error
  • ModelError() - Returns model validation errors
  • IdentityError(result, message) - Returns identity operation errors

Response Structure

All responses follow this structure:

{
  "type": "API",
  "success": true,
  "code": "0000",
  "message": "Operation completed successfully.",
  "data": { ... },
  "error": null,
  "statusCode": 200
}

License

MIT License

Repository

https://github.com/qne/AccountingOnline

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  net9.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
1.0.9 163 3/11/2026
1.0.8 111 2/28/2026
1.0.7 111 2/27/2026
1.0.6 115 1/23/2026
1.0.4 151 12/12/2025
1.0.3 478 12/10/2025
1.0.2 364 12/8/2025
1.0.1 360 12/8/2025
1.0.0 421 11/18/2025