API.Common.Response.Models 1.0.2

dotnet add package API.Common.Response.Models --version 1.0.2                
NuGet\Install-Package API.Common.Response.Models -Version 1.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="API.Common.Response.Models" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add API.Common.Response.Models --version 1.0.2                
#r "nuget: API.Common.Response.Models, 1.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.
// Install API.Common.Response.Models as a Cake Addin
#addin nuget:?package=API.Common.Response.Models&version=1.0.2

// Install API.Common.Response.Models as a Cake Tool
#tool nuget:?package=API.Common.Response.Models&version=1.0.2                

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);
}

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

    • No dependencies.

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.2 77 1/17/2025
1.0.1 68 1/16/2025
1.0.0 63 1/16/2025

- Update README.md