Skip to content

[Backend] Set X-Idempotent-Replayed response header from idempotency middleware #884

@ogazboiz

Description

@ogazboiz

Join the contributor Telegram: https://t.me/+DOylgFv1jyJlNzM0

Why this matters

/api/loans/:loanId/repay/build and similar write endpoints do not provide an idempotency cache hit response that tells the client "this was already processed". Today, when a client retries with the same Idempotency-Key, it does receive a cached result but without a clear X-Idempotent-Replayed: true header. Adding it lets the frontend distinguish "first success" from "retried" so the UI can de-duplicate toasts and avoid double-counting transactions.

Acceptance criteria

  • In idempotencyMiddleware, when a cached entry is found, set response header X-Idempotent-Replayed: true before forwarding the cached body.
  • On fresh execution, set X-Idempotent-Replayed: false.
  • Add a Jest test asserting both header values across two sequential requests with the same key.
  • Document the header in the docs/wiki/ or README for API consumers.

Files to touch

  • backend/src/middleware/idempotency.ts
  • backend/src/middleware/__tests__/idempotency.test.ts
  • docs/wiki/api-idempotency.md (new) or short note in an existing wiki page

Out of scope

  • Changing the cache backend or TTL.
  • Replaying side effects (the current design is response-only replay, which is correct).

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbackendIssues related to backend developmentgood first issueGood for newcomers

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions