Istanbul.ApiIdempotency.Core 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Istanbul.ApiIdempotency.Core --version 1.0.2                
NuGet\Install-Package Istanbul.ApiIdempotency.Core -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Istanbul.ApiIdempotency.Core" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Istanbul.ApiIdempotency.Core --version 1.0.2                
#r "nuget: Istanbul.ApiIdempotency.Core, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Istanbul.ApiIdempotency.Core as a Cake Addin
#addin nuget:?package=Istanbul.ApiIdempotency.Core&version=1.0.2

// Install Istanbul.ApiIdempotency.Core as a Cake Tool
#tool nuget:?package=Istanbul.ApiIdempotency.Core&version=1.0.2                

About Istanbul.ApiIdempotency

What is Idempotency?

Idempotency is a term given to certain operations in mathematics and computer science. In mathematics, it can be seen when we multiply any number by 1. It doesn’t matter how many times we perform this operation the result will be always same.

It is also very important concept in computer science. Idempotency concept is allowing you to retry a request multiple times while only performing the action once. Let's imagine that you have an api which is responsible for accepting payments for a specific order. From client application perspective there are many situations (timeouts, network issues, application failures, bugs and even clicking "complete" button more than one time) which might require safely retrying the same operation with the guarantee that the operation will only be executed once.

Getting Started

Istanbul.ApiIdempotency is a .net package which focuses on helping developers to implement this concept easily to their applications. Package is supporting Redis as data store at the moment but it also allows you to extend it and work with some other data stores. Implementation for other data stores is in my roadmap.

Installation

You can install Istanbul.ApiIdempotency with NuGet:

Install-Package Istanbul.ApiIdempotency
Install-Package Istanbul.ApiIdempotency.Redis.StackExchange

Or via the .NET Core command line interface:

dotnet add package Istanbul.ApiIdempotency
dotnet add package Istanbul.ApiIdempotency.Redis.StackExchange

Usage

Package is designed to work with different data stores and it supports Redis at the moment. There are different Redis c# drivers available in order to connect and use Redis so I decided to provide different idempotency data store packages for different Redis drivers.

First version of RedisApiIdempotencyDataStoreProvider supports StackExchange driver so that's why it accepts IConnectionMultiplexer as constructor parameter. You are free to configure IConnectionMultiplexer as you wish.

Configure settings:

var redisConnectionMultiplexer = ConnectionMultiplexer.Connect("localhost");

services.AddApiIdempotency(options =>
{
    options.IdempotencyHeaderKey = "X-Idempotency-Key";
    options.IdempotencyDataStoreProvider = new RedisApiIdempotencyDataStoreProvider(redisConnectionMultiplexer);
});

Use idempotency:

app.UseApiIdempotency();

Activate idempotency with 20 seconds of timeout:

[HttpPost]
[Route("api/[controller]/create")]
[ApiIdempotency(20)]
public IActionResult Create()
{
    return Ok(new { OrderCreationDate = DateTime.Now });
}

Roadmap

  • Creating basic idempotency package
  • Nuget availability
  • Auto generated idempotency keys
  • Allowing project to provide key (not only from request header)
  • Supporting more data stores
    • Couchbase
    • Memcached

See the open issues for a full list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue. Don't forget to give the project a star 😄

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Istanbul.ApiIdempotency.Core:

Package Downloads
Istanbul.ApiIdempotency

Istanbul.ApiIdempotency is a .net package which focuses on helping developers to implement idempotency concept easily to their applications.

Istanbul.ApiIdempotency.Redis.StackExchange

Istanbul.ApiIdempotency.Redis.StackExchange is Redis data store provider (based on StackExchange) of Istanbul.ApiIdempotency .net package which focuses on helping developers to implement idempotency concept easily to their applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.5 715 2/23/2022
1.0.4 646 2/23/2022
1.0.3 638 2/20/2022
1.0.2 635 2/17/2022
1.0.1 642 2/17/2022
1.0.0 632 2/17/2022