{"id":24988689,"url":"https://github.com/lucasmontagnani/idempotentapi","last_synced_at":"2025-10-23T07:44:40.222Z","repository":{"id":274740745,"uuid":"923919503","full_name":"lucasMontagnani/IdempotentApi","owner":"lucasMontagnani","description":"This project explores different ways to handle API idempotency. It implements service injection, action filters, and middleware to enforce idempotency in POST requests, using an In-Memory database for testing.","archived":false,"fork":false,"pushed_at":"2025-01-30T18:56:18.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-05T10:49:26.532Z","etag":null,"topics":["api","csharp","idempotency","netcore","rest-api"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lucasMontagnani.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-01-29T04:18:21.000Z","updated_at":"2025-01-30T19:00:41.000Z","dependencies_parsed_at":"2025-06-05T10:35:53.929Z","dependency_job_id":"75b19190-16e3-4a5d-9c5b-565ee9cb7fb5","html_url":"https://github.com/lucasMontagnani/IdempotentApi","commit_stats":null,"previous_names":["lucasmontagnani/idempotentapi"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lucasMontagnani/IdempotentApi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasMontagnani%2FIdempotentApi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasMontagnani%2FIdempotentApi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasMontagnani%2FIdempotentApi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasMontagnani%2FIdempotentApi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucasMontagnani","download_url":"https://codeload.github.com/lucasMontagnani/IdempotentApi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasMontagnani%2FIdempotentApi/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260035586,"owners_count":22949253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","csharp","idempotency","netcore","rest-api"],"created_at":"2025-02-04T12:05:03.662Z","updated_at":"2025-10-23T07:44:35.189Z","avatar_url":"https://github.com/lucasMontagnani.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IdempotentApi\n\n## Overview\n\nThis project, IdempotencyAPI, was created to explore different ways to handle API idempotency. Existing NuGet packages caused conflicts with parts of the code, leading to errors, so I implemented custom solutions.\n\nTo demonstrate these solutions, the project includes several endpoints that validate idempotency in different ways. An in-memory database is used with a single Product model to test the results.\n\n## Endpoints\n### Product Retrieval\n\u003cUL\u003e\n  \u003cLI\u003eGET /GetProductsById - Retrieves a product by its ID.\u003c/LI\u003e\n  \u003cLI\u003eGET /GetProducts - Retrieves all products currently stored in the database.\u003c/LI\u003e\n\u003c/UL\u003e\n\n### Product Creation\n\n\u003cUL\u003e\n  \u003cLI\u003ePOST /CreateProduct - A standard product creation endpoint (control case) without idempotency validation.\u003c/LI\u003e\n\u003c/UL\u003e\n\n### Idempotent Product Creation\n\nEach of the following endpoints requires a header Idempotency-Key, which must be a valid GUID.\n\u003cUL\u003e\n  \u003cLI\u003ePOST /CreateProductIdempotentWithServiceInjection\u003c/LI\u003e\n      \u003cUL\u003e\u003cLI\u003eUses an IdempotencyService, injected via Dependency Injection in the controller, to validate the request.\u003c/LI\u003e\u003c/UL\u003e\n  \u003cLI\u003ePOST /CreateProductIdempotentWithFilter\u003c/LI\u003e\n      \u003cUL\u003e\u003cLI\u003eUses an Action Filter triggered by the [ServiceFilter] attribute on the endpoint to validate idempotency.\u003c/LI\u003e\u003c/UL\u003e\n  \u003cLI\u003ePOST /CreateProductIdempotentWithMiddleware\u003c/LI\u003e\n      \u003cUL\u003e\u003cLI\u003eUses Middleware to validate idempotency. This is applied globally to all POST requests that include the Idempotency-Key header.\u003c/LI\u003e\u003c/UL\u003e\n\u003c/UL\u003e\n\n## Comparison of Idempotency Approaches\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003eApproach\u003c/th\u003e\n    \u003cth\u003ePros\u003c/th\u003e\n    \u003cth\u003eCons\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eService Injection\u003c/td\u003e\n    \u003ctd\u003eSimple to implement\u003c/td\u003e\n    \u003ctd\u003eIncreases code dependency and coupling\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eAction Filter\u003c/td\u003e\n    \u003ctd\u003eLoose coupling, applies idempotency selectively\u003c/td\u003e\n    \u003ctd\u003eSlightly more setup required\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eMiddleware\u003c/td\u003e\n    \u003ctd\u003eLoose coupling, automatically applies to all POSTs\u003c/td\u003e\n    \u003ctd\u003eApplies idempotency to all POST endpoints\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n## Conclusion\n\nAmong the three approaches, Action Filters offer the best balance between flexibility and maintainability, allowing idempotency to be applied selectively while keeping the code loosely coupled.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucasmontagnani%2Fidempotentapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucasmontagnani%2Fidempotentapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucasmontagnani%2Fidempotentapi/lists"}