ApiResponse.Json 1.0.5

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

ApiResponse.Json

A lightweight helper for returning consistent JSON responses from ASP.NET Core Web APIs with proper HTTP status codes.

Installation

  • NuGet Package Manager:

Install-Package ApiResponse.Json

- .NET CLI:
```bash
dotnet add package ApiResponse.Json

Usage

Import the namespace and use the static helpers in your controllers.

using Microsoft.AspNetCore.Mvc;
using ApiResponse.Json;

[ApiController]
[Route("api/[controller]")]
public class SampleController : ControllerBase
{
    [HttpGet("success")]
    public IActionResult GetSuccess()
    {
        var data = new { Name = "John Doe", Age = 30 };
        return ApiResponse.Ok(data, "Data retrieved successfully");
    }

    [HttpPost("created")]
    public IActionResult CreateItem()
    {
        var newItem = new { Id = 1, Name = "Item 1" };
        return ApiResponse.Created(newItem, "Item created successfully");
    }

    [HttpGet("error")]
    public IActionResult GetError()
    {
        return ApiResponse.InternalServerError("Something went wrong");
    }
}

Available Methods

Method Default Message HTTP Status
ApiResponse.Ok(...) OK 200
ApiResponse.Created(...) Created 201
ApiResponse.Accepted(...) Accepted 202
ApiResponse.BadRequest(...) Bad Request 400
ApiResponse.Unauthorized(...) Unauthorized 401
ApiResponse.NotFound(...) Not Found 404
ApiResponse.InternalServerError(...) Internal Server Error 500

Each success helper has two overloads:

  • Provide data, message, and success (optional).
  • Or pass a fully constructed ApiResponse instance.

Example JSON Output

{
  "data": {
    "name": "John Doe",
    "age": 30
  },
  "message": "Data retrieved successfully",
  "success": true
}

License

This project is licensed under the MIT License.

Product 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. 
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.5 227 8/11/2025