NetCoreKit.CleanResponse
1.0.1
dotnet add package NetCoreKit.CleanResponse --version 1.0.1
NuGet\Install-Package NetCoreKit.CleanResponse -Version 1.0.1
<PackageReference Include="NetCoreKit.CleanResponse" Version="1.0.1" />
<PackageVersion Include="NetCoreKit.CleanResponse" Version="1.0.1" />
<PackageReference Include="NetCoreKit.CleanResponse" />
paket add NetCoreKit.CleanResponse --version 1.0.1
#r "nuget: NetCoreKit.CleanResponse, 1.0.1"
#:package NetCoreKit.CleanResponse@1.0.1
#addin nuget:?package=NetCoreKit.CleanResponse&version=1.0.1
#tool nuget:?package=NetCoreKit.CleanResponse&version=1.0.1
NetCoreKit.CleanResponse
A lightweight and simple Result Wrapper library for .NET applications.
NetCoreKit.CleanResponse helps developers create consistent and standardized API responses for both success and failure scenarios.
Instead of returning different response structures in every API endpoint, this library ensures a single predictable response format across your application.
Installation
Install the package using NuGet:
dotnet add package NetCoreKit.CleanResponse
Why Use NetCoreKit.CleanResponse?
Without a response wrapper, APIs often return inconsistent responses.
Example:
{ "name": "John" }
or
{ "error": "User not found" }
Different response formats make frontend integration and error handling difficult.
Using NetCoreKit.CleanResponse, your APIs always return a consistent structure:
{
"success": true,
"message": "User fetched successfully",
"data": {
"name": "John"
}
}
Response Structure
Every response generated by this library follows this format:
{
"success": true,
"message": "Operation completed",
"data": {}
}
Field Description:
| Field | Description |
|---|---|
| success | Indicates whether the operation succeeded |
| message | A message describing the result |
| data | The data returned by the operation |
Getting Started
Import the namespace in your project:
using NetCoreKit.CleanResponse;
Usage Examples
1. Success Response With Data
var user = new User { Name = "John" };
return Result<User>.SuccessResult(user, "User fetched successfully");
Response:
{
"success": true,
"message": "User fetched successfully",
"data": {
"name": "John"
}
}
2. Failure Response
return Result<string>.Failure("User not found");
Response:
{
"success": false,
"message": "User not found",
"data": null
}
3. Success Response Without Data
return Ok(Result.SuccessResult("Operation completed successfully"));
Response:
{
"success": true,
"message": "Operation completed successfully"
}
4. Failure Response Without Data
return Ok(Result.Failure("Operation failed"));
Response:
{
"success": false,
"message": "Operation failed"
}
Example Usage in ASP.NET Controller
[HttpGet]
public IActionResult GetUser()
{
var user = new User
{
Name = "John"
};
return Ok(Result<User>.SuccessResult(user, "User fetched successfully"));
}
Benefits
- Standardized API responses
- Cleaner controller code
- Simplified success and failure handling
- Easy integration with ASP.NET APIs
- Reusable across multiple projects
- Reduces repetitive response models
Target Framework
This package supports modern .NET applications and works seamlessly with ASP.NET APIs.
Contributing
Contributions, issues, and feature requests are welcome.
If you'd like to improve this project, feel free to submit a pull request.
License
MIT License
Author
Created and maintained by Pawan Dhekwar
| Product | Versions 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
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.