![]() |
VOOZH | about |
dotnet add package Aiska.IdempotentApi.Hybrid --version 1.0.6
NuGet\Install-Package Aiska.IdempotentApi.Hybrid -Version 1.0.6
<PackageReference Include="Aiska.IdempotentApi.Hybrid" Version="1.0.6" />
<PackageVersion Include="Aiska.IdempotentApi.Hybrid" Version="1.0.6" />Directory.Packages.props
<PackageReference Include="Aiska.IdempotentApi.Hybrid" />Project file
paket add Aiska.IdempotentApi.Hybrid --version 1.0.6
#r "nuget: Aiska.IdempotentApi.Hybrid, 1.0.6"
#:package Aiska.IdempotentApi.Hybrid@1.0.6
#addin nuget:?package=Aiska.IdempotentApi.Hybrid&version=1.0.6Install as a Cake Addin
#tool nuget:?package=Aiska.IdempotentApi.Hybrid&version=1.0.6Install as a Cake Tool
A .NET library for creating idempotent APIs, ensuring that requests are processed only once, even if received multiple times.
Making your APIs reliable and resilient with idempotency.
👁 License
👁 GitHub stars
👁 GitHub forks
👁 GitHub issues
👁 GitHub pull requests
👁 GitHub last commit
👁 GitHub contributors
👁 .NET
👁 C#
👁 NuGet Version
👁 NuGet Downloads
Aiska.IdempotentApi is a .NET library designed to simplify the implementation of idempotent APIs. Idempotency is a crucial property for ensuring that an API request, when made multiple times, has the same effect as if it were made only once. This is particularly important in distributed systems where network issues can lead to requests being retried.
This library provides a straightforward way to wrap your API endpoints, ensuring that requests with the same idempotency key are processed only once. It handles the storage and retrieval of request results, preventing duplicate processing and ensuring data consistency.
The library is built using C# and targets .NET. It's designed to be lightweight and easy to integrate into existing .NET projects. The core architecture involves intercepting API requests, checking for an existing result based on the idempotency key, and either returning the stored result or processing the request and storing the result for future use.
Here is Diagram process base on draft-ietf :
<a id="features"></a>
<a id="quick-Start"></a>
Install the NuGet package and add the necessary code to your ASP.NET Core pipeline.
Install-Package Aiska.IdempotentApi
// In your Startup.cs or Program.cs
public void ConfigureServices(IServiceCollection services)
{
builder.Services.AddIdempotentApi(builder.Configuration);
// Other service configurations
}
<a id="installation"></a>
Install-Package Aiska.IdempotentApi
# Clone the repository
git clone https://github.com/aiska/Aiska.IdempotentApi.git
cd Aiska.IdempotentApi
# Build the project
dotnet build
<a id="usage"></a>
Add the Idempotency Service: In your Program.cs or Startup.cs, add the AddIdempotency service.
// Program.cs or Startup.cs
builder.Services.AddIdempotency(); // For .NET 6+
// OR
services.AddIdempotency(); // For .NET Core 3.1 and .NET 5
Add the Idempotency Filter: Add the AddIdempotentFilter Filter your Endpoint Minimal Api.
// Program.cs or Startup.cs
todosApi.MapPost("/", async (Todo todo) =>
{
// simulate creation
return Results.Created($"/todoitems/{todo.Id}", todo);
}).AddIdempotentFilter();
Or **Apply the [Idempotent] attribute to your controller actions **:
using Microsoft.AspNetCore.Mvc;
using Aiska.IdempotentApi;
[ApiController]
[Route("[controller]")]
public class MyController : ControllerBase
{
[HttpPost]
[Idempotent]
public IActionResult MyAction([FromBody] MyRequest request)
{
// Your logic here
return Ok(new { Message = "Request processed successfully" });
}
}
public class MyRequest
{
public string Data { get; set; }
}
Include an Idempotency-Key Header: Send an Idempotency-Key header with your API request. The value should be a unique identifier for the request.
POST /MyController/MyAction HTTP/1.1
Content-Type: application/json
Idempotency-Key: unique-request-id
{
"data": "some data"
}
For more advanced configuration options, see the Configuration section.
<a id="configuration"></a>
The default header name is Idempotency-Key. You can customize this:
builder.Services.AddIdempotentApi(options =>
{
options.KeyHeaderName = "X-Idempotency-Key";
options.ExpirationFromMinutes = 5;
});
The default Cache expiration name is 5. You can customize this:
builder.Services.AddIdempotentApi(options =>
{
options.ExpirationFromMinutes = 10;
});
By default, the library uses an in-memory storage provider. For production environments, you'll want to implement a persistent storage provider (e.g., using Redis or a database).
// Example (not a complete implementation)
public class CustomIdempotencyStore : IIdempotencyStore
{
// Implement the IIdempotencyStore interface methods (GetAsync, SetAsync, etc.)
}
builder.Services.AddSingleton<IIdempotencyStore, CustomIdempotencyStore>();
<a id="project-structure"></a>
Aiska.IdempotentApi/
├── src/
│ ├── Aiska.IdempotentApi/
│ │ ├── Abtractions/ # Idempotent Abtractions
│ │ ├── Attributes/ # Idempotent Attribute
│ │ ├── Extensions/ # Extension methods for IServiceCollection and IApplicationBuilder
│ │ ├── Filters/ # Filter to check for Idempotency
│ │ ├── Middleware/ # Idempotency Middleware
│ │ ├── Models/ # Models for storing results
│ │ ├── Options/ # Options for configuring the middleware
│ │ ├── Services/ # Idempotency Service and Store interfaces
│ │ └── ...
│ └── Aiska.IdempotentApi.csproj # Project file
├── LICENSE # License file
└── README.md # This file
<a id="contributing"></a>
We welcome contributions! Please see our (placeholder - create this file) for details.
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)# Fork and clone the repo
git clone https://github.com/aiska/Aiska.IdempotentApi.git
# Navigate to the project directory
cd Aiska.IdempotentApi
# Build the project
dotnet build
# Run tests
dotnet test
dotnet format before committing<a id="testing"></a>
To run the tests:
dotnet test
<a id="license"></a>
This project is licensed under the MIT License - see the file for details.
<a id="support"></a>
<a id="acknowledgments"></a>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.6 | 262 | 12/7/2025 |