logo

A .NET library for building custom API response.

Installation

Use the package manager Nuget to install Smart Response.

NuGet\Install-Package SmartResponse

Usage

using SmartResponse;

# register Smart Response in services.
builder.Services.AddSmartResponse();

# create response model.
var response = ResponseManager<bool>.Create();

# return error.
return response.Set(MessageCode.Required, "Name");

# append errors.
response.Append(MessageCode.InbetweenValue, "Age", "18", "25");

response.Append(MessageCode.InvalidMinLength, "Name", "Name", "10");

return response.Build();

# return error using fluent validation.
RuleFor(u => u.Username)
    .NotNull().SmartResponse(MessageCode.Required);

RuleFor(u => u.Username)
    .Length(10, 50).SmartResponse(MessageCode.InbetweenValue, "10", "50");