Sindika.AspNet.RequestResponse 1.3.0

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

Sindika.AspNet Request-Response Library

This library provides a standard framework for creating and managing API request and response structures in .NET applications. It simplifies the development process by offering reusable components for handling common request/response patterns.

Features

  • Standardized Requests:
    • Supports custom headers, options, and data payloads.
    • Includes base request models for general-purpose usage.
  • Standardized Responses:
    • Provides success and error responses with detailed metadata.
    • Includes reusable models for error details, form validation errors, and more.
  • Helper Utilities:
    • Simplifies the creation of success and error responses.

Installation

Add the library to your project via NuGet:

dotnet add package Sindika.AspNet.RequestResponse

Usage

Request Models

BaseRequest

Encapsulates headers, data, and options for API requests.

var request = new BaseRequest<MyData>
{
    Header = new HeaderRequest { Authorization = "Bearer my-token" },
    Data = new MyData { /* Populate data */ },
    Options = new OptionRequest
    {
        ShowError = true,
        RollbackOnFailure = true,
        ShowInfo = false
    }
};
SingleUpsertRequest

Handles operations requiring key-value pairs for single upserts.

var upsertRequest = new SingleUpsertRequest<MyValue>
{
    Key = new Dictionary<string, object> { { "Id", 123 } },
    Value = new MyValue { /* Populate value */ }
};

Response Models

BaseResponse

Provides a consistent structure for all API responses.

var successResponse = new BaseResponse<MyData, object?>
{
    Success = true,
    Code = "SUC-001",
    Message = "Operation succeeded.",
    Data = new MyData { /* Populate data */ },
    Info = new InfoResponse
    {
        TransactionId = Guid.NewGuid().ToString(),
        Timestamp = DateTime.UtcNow.ToString("o"),
        OperationType = "Create"
    }
};
ErrorResponse

Represents error details for failed operations, including form and field-level errors.

var errorResponse = new ErrorResponse<object>
{
    Data = null,
    ErrorDetails = new ErrorDetailResponse
    {
        FormErrors = new List<FormErrorResponse>
        {
            new FormErrorResponse
            {
                Code = "ERR-FRM-001",
                Message = "Invalid input",
                Fields = new List<string> { "Name", "Email" }
            }
        }
    }
};

Helper Methods

Use ResponseHelper to create responses with minimal code:

Success Response
var successResponse = ResponseHelper.Success(
    data: new MyData { /* Populate data */ },
    code: "SUC-002",
    message: "Data retrieved successfully",
    info: new InfoResponse { TransactionId = "12345" }
);
Error Response
var errorResponse = ResponseHelper.Error<MyData, object>(
    data: null,
    code: "ERR-001",
    message: "Validation failed",
    errors: new List<ErrorResponse<object>>
    {
        new ErrorResponse<object>
        {
            Data = null,
            ErrorDetails = new ErrorDetailResponse
            {
                FieldErrors = new List<FieldErrorResponse>
                {
                    new FieldErrorResponse
                    {
                        Field = "Name",
                        Code = "ERR-VAL-001",
                        Message = "Name is required"
                    }
                }
            }
        }
    }
);

Classes Overview

Requests

  • BaseRequest<T>: Encapsulates HeaderRequest, OptionRequest, and Data of type T.
  • HeaderRequest: Contains request-specific headers like Authorization.
  • OptionRequest: Provides flags for request behavior, such as ShowError and RollbackOnFailure.
  • SingleUpsertRequest<T>: Used for upsert operations requiring a key-value mapping.

Responses

  • BaseResponse<T, Y>: General structure for API responses, including metadata, data, and errors.
  • ErrorDetailResponse: Contains details about validation or operational errors.
  • ErrorResponse<T>: Represents individual error data.
  • FieldErrorResponse: Error details for specific fields in a request.
  • FormErrorResponse: Form-level error details with associated fields.
  • InfoResponse: Metadata for successful operations, including TransactionId, Timestamp, and more.

For detailed documentation, examples, and FAQs, visit our official documentation.

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. 
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 Sindika.AspNet.RequestResponse:

Package Downloads
Sindika.AspNet.Common

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.0 1,294 3 months ago
1.2.0 88 3 months ago
1.1.0 82 3 months ago
1.0.0 81 3 months ago