Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

MB.ResponseResult

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

MB.ResponseResult

A lightweight and flexible API response model for structured responses.

nugetNuGet
Version
1.0.4.5
Version published
Maintainers
1
Created
Source

MB.ResponseResult Package 📦

A standardized API response library for ASP.NET Core, featuring multi-language support and seamless integration.

👅 Installation

dotnet add package MB.ResponseResult

🚀 Quick Start

  • Register Services (Program.cs)
#Basic Usage#
builder.Services.AddResponseResultServices();

Or

#Multiple-Language Support#
builder.Services.AddResponseResultServices(options =>
{
    options.IsMultipleLang = true; // Enable multi-language support
});

🎯 Response Breakdown

🔧 Core Methods

MethodStatus CodeParametersExample
ResponseSuccess()CustomstatusCode, message, dataApiResponse.ResponseSuccess(HttpStatusCode.Accepted, "Processing", data)
ResponseFail()CustomstatusCode, message, errors, dataApiResponse.ResponseFail(HttpStatusCode.TooManyRequests, "Rate limited", errors)

✅ Success Helpers (Built with ResponseSuccess)

MethodStatus CodeEquivalent ToExample
Created()201ResponseSuccess(201, message, data)ApiResponse.Created(product)
Ok(data)200ResponseSuccess(200, "Ok", data)ApiResponse.Ok(user)
NoContent()204ResponseSuccess(204, message)ApiResponse.NoContent()

❌ Error Helpers (Built with ResponseFail)

MethodStatus CodeEquivalent ToExample
NotFound()404ResponseFail(404, message)ApiResponse.NotFound("User not found")
BadRequest()400ResponseFail(400, message, errors)ApiResponse.BadRequest(errors)
ValidationError()422ResponseFail(422, message, errors)ApiResponse.ValidationError(errors)
InternalServerError()500ResponseFail(500, message)ApiResponse.InternalServerError()

🔑 Key Features

Standardized Format

All responses follow the same consistent structure:

{  
  "data": {},        // Response payload (object)  
  "message": "Operation succeeded",  // Human-readable message  
  "statusCode": 200, // HTTP status code  
  "status": true,    // Boolean success indicator  
  "errors": []       // List of errors (if any)  
}

Seamless Conversion

Convert ApiResponse to IActionResult automatically using:

.AsResult() for synchronous responses : ApiResponse.Ok().AsResult();

.AsResultAsync() for asynchronous responses : ApiResponse.Ok().AsResultAsync();

🌍 Localization (Multi-Language Support)

Localization Ready

Message keys like "Ok" or "NotFound" can be localized by implementing IResultLocalizationService.

1.Implement a IResultLocalizationService Localization Service

 public class CustomLocalizationService : IResultLocalizationService
 {
     public string GetLocalizedMessage(string messageKey, string languageCode)
     {
         //Your own logic
         
     }
 
     public Task<string> GetLocalizedMessageAsync(string messageKey, string languageCode)
     {
         //Your own logic
     }
 }

2.Register the service in the program.cs

builder.Services.AddScoped<IResultLocalizationService, CustomLocalizer>();

This README provides a quick guide to integrate and use the package effectively. Expand the documentation for advanced scenarios. 😊

Keywords

api

FAQs

Package last updated on 14 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts