ARConsistency 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ARConsistency --version 1.1.0
NuGet\Install-Package ARConsistency -Version 1.1.0
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="ARConsistency" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ARConsistency --version 1.1.0
#r "nuget: ARConsistency, 1.1.0"
#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 ARConsistency as a Cake Addin
#addin nuget:?package=ARConsistency&version=1.1.0

// Install ARConsistency as a Cake Tool
#tool nuget:?package=ARConsistency&version=1.1.0

Read this document in different languages : Türkçe

ARConsistency

.NET Core Nuget GitHub

ARConsistency maintains response consistency by ensuring that all responses sent to the client for .Net Core Web Api projects are forwarded with the same template.

Setup

1. Install the Nuget Package

You can include this library in your project with the Nuget package.

Add the nuget package to your project using Package Manager Console or Nuget Package Manager.

PM> Install-Package ARConsistency

Or using .Net Cli

> dotnet add package ARConsistency
2. Settings

Add the following configuration to the "appsettings.json" file of your project.

"ApiConsistency": {
  "IsDebug": true,
  "ShowStatusCode": true,
  "ShowApiVersion": false,
  "ApiVersion": "1.0",
  "IgnoreNullValue": true,
  "UseCamelCaseNaming": true,
  "EnableExceptionLogging": true
}

Note: If you wish, you can assign these settings manually in the next step without reading them from the config file. This step is optional.

3. Startup Implementation

Add the following into "Startup.cs".

public void ConfigureServices(IServiceCollection services)
{
  // ...
  services.AddControllers()
          .AddApiResponseConsistency(config => Configuration.GetSection("ApiConsistency").Bind(config) );
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
  app.UseApiResponseConsistency();
  // ...
}

Sample #1

public IActionResult Get()
{
  return Ok(_astronauts.FirstOrDefault());
}

Response

{
  "statusCode":  200,
  "isError":  false,
  "payload":  {
    "Id":  1,
    "Name":  "Neil",
    "Surname":  "Armstrong"
  }
}

Sample #2

public IActionResult Get()
{
  return new ApiResponse("Request successful.", _astronauts.FirstOrDefault(), 200, "2.0");
}

Response

{
  "statusCode":  200,
  "version":  "2.0",
  "message":  "Request successful.",
  "isError":  false,
  "payload":  {
    "Id":  1,
    "Name":  "Neil",
    "Surname":  "Armstrong"
  }
}

Response Types

ARConsistency works with three types of responses of its own. The basic information of these classes are as follows.

Class Name HTTP Status Code Description
ApiResponse 200 (OK) It provides data return for successful response.
ApiError 400 (BadRequest) Report any error to the client
ApiException 500 (Internal Server Error) Throws errors and terminates the operation of the current procedure.

In addition to these response types, ARConsistency also supports basic web api return types such as Ok(), BadRequest(). But Ok() return type contains only the data ApiResponse can contain information such as Message in addition to the returned data.

The HTTP Status Codes in the table above are default values and can be changed during use.

Logging

ARConsistency has the ability to log errors it captures with the ILogger interface. This setting (EnableExceptionLogging) is enabled by default unless you change it.

While this setting is on, errors occurring in the pipeline are transmitted to the logging mechanism via the ILogger interface and the summary of the error message is returned to the user as ApiExcepiton type api response. If the IsDebug option is on, the details of the error message are also included in the response.

When logging is turned off, error messages captured are thrown without processing.

Test Api Documentation

There is a .Net Core Web Api project in the repository where you can test the project. You can find the Postman documentation of the test api here.

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. 
.NET Core netcoreapp3.1 is compatible. 
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.2.4 997 4/9/2021
1.2.1 489 12/18/2020
1.2.0 454 11/17/2020
1.1.2 496 11/5/2020
1.1.0 547 7/17/2020
1.0.4 503 4/22/2020
1.0.3 536 4/19/2020
1.0.2 566 4/10/2020
1.0.1 519 3/29/2020
1.0.0 513 3/29/2020