https://github.com/furkandeveloper/idempotentsharp
IdempotentSharp allows you to develop idempotent endpoints.
https://github.com/furkandeveloper/idempotentsharp
dotnet hybridcache idempotency idempotent idempotent-requests minimal-api
Last synced: 3 months ago
JSON representation
IdempotentSharp allows you to develop idempotent endpoints.
- Host: GitHub
- URL: https://github.com/furkandeveloper/idempotentsharp
- Owner: furkandeveloper
- License: mit
- Created: 2025-01-11T19:30:50.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-01-19T16:04:11.000Z (9 months ago)
- Last Synced: 2025-04-30T13:15:12.052Z (5 months ago)
- Topics: dotnet, hybridcache, idempotency, idempotent, idempotent-requests, minimal-api
- Language: C#
- Homepage:
- Size: 36.1 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# IdempotentSharp
![]()
## Give a Star 🌟
If you liked the project or if **IdempotentSharp** helped you, please give a star.### Purpose
**IdempotentSharp** allows you to develop idempotent endpoints.### How To Use(?)
### Install
If you are using Minimal API```bash
dotnet add package IdempotentSharp.AspNetCore.MinimalApi
```If you are using Controller
```bash
dotnet add package IdempotentSharp.AspNetCore
```To use the `IdempotentSharp` library, you must configure the `Hybrid Cache` feature.
```csharp
builder.Services.AddHybridCache(options =>
{
// Maximum size of cached items
options.MaximumPayloadBytes = 1024 * 1024 * 10; // 10MB
options.MaximumKeyLength = 512;// Default timeouts
options.DefaultEntryOptions = new HybridCacheEntryOptions
{
Expiration = TimeSpan.FromSeconds(30),
LocalCacheExpiration = TimeSpan.FromSeconds(30)
};
});
```
If you are using redis:
```csharp
builder.Services.AddStackExchangeRedisCache(options =>
{
options.Configuration = "{your_connection_string}";
});
```
Now everything is ready.You can give this feature to any endpoint you want with the idempotent attribute.
```csharp
[ApiController]
[Route("[controller]")]
public class HomeController : ControllerBase
{
private readonly List Response = ["value1", "value2", "value3"];
[HttpGet]
[Idempotent]
public async Task GetAsync()
{
return Ok(Response);
}
}
```When the endpoint with the attribute added runs, it throws an error if it cannot find the `X-Request-Id` value from the headers.
For Minimal Api:
```csharp
var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};app.MapGet("/weatherforecast", () =>
{
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return Results.Ok(forecast);
})
.WithName("GetWeatherForecast")
.WithOpenApi()
.AddEndpointFilter();
```## Star History
[](https://star-history.com/#furkandeveloper/IdempotentSharp&Date)