API.Common.Response.Models 1.0.4

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

API Common Response Models Package

Table of Contents

  1. Introduction
  2. Usage Guide
  3. Links

Introduction


This package provides an essay way to work with responses when building APIs.

Usage Guide


Download the package API.Common.Response.Models.' There is no need to register anything in the service collection. We have a couple of classes

  • ApiBaseResponse is the base class from which all other response classes inherits. This class is intended to be the only you return from all your methods. You can then return the sub-classes within your methods based on the scenario.
  • OkResponse is the response type returned when everything is OK.
  • BadRequestResponse is the response when a request is invalid.
  • NotFoundResponse is the response returned when the resource is not found.
  • ForbiddenResponse is the response sent when a client is not have access to a resource.
  • UnauthorizedResponse is the class returned when a request is unauthorized
  • InternalServerErrorResponse included in verion 1.0.2 for unhandled exceptions.

Check out the Github Repository to see the implementations.

public async Task<ApiBaseResponse> GetAsync(Guid id)
{
	if(id == Guid.Empty)
	{
		return new BadRequestResponse("Invalid id")
	}

	var data = await _repository.GetDataAsync(id);
	if(data == null)
	{
		return new NotFoundResponse("Record not found");
	}

	return new OkResponse<DataModel>(data);
}

Return Responses

//
//Inherit the ApiControllerBase class in the controller instead of the ControllerBase class to use th ProcessError() method
public class UserController : ApiBaseController
{
	// some codes removed

	[HttpGet("{id}")]
	public async Task<IActionResult> Get([FromRoute] Guid id)
	{
		var baseResult = await _service.GetById(id);
		if (!baseResult.Success)
			return ProcessError(baseResult);

		return Ok(baseResult.GetResult<bool>());
	}
}

To view the source code or get in touch:

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on API.Common.Response.Models:

Package Downloads
DiagnosKit.Core

A shared toolkit for cross-cutting concerns such as global error handling and logging.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4 185 8/14/2025
1.0.3 155 8/14/2025
1.0.2 238 1/17/2025
1.0.1 108 1/16/2025
1.0.0 107 1/16/2025

- Update README.md