gin-basic

command
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 7 Imported by: 0

README

Gin Basic Example

This example demonstrates basic idempotency handling with Gin Gonic using in-memory storage.

Running the Example

cd examples/gin-basic
go run main.go

Testing Idempotency

First Request (New)
curl -X POST http://localhost:8080/payment \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: payment-001' \
  -d '{"amount":100.50,"currency":"USD"}'

Response:

{
  "status": "success",
  "amount": 100.50,
  "currency": "USD",
  "timestamp": 1708123456
}
Second Request (Cached)

Same request with same idempotency key:

curl -X POST http://localhost:8080/payment \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: payment-001' \
  -d '{"amount":100.50,"currency":"USD"}'

Response (with X-Idempotent-Replayed: true header):

{
  "status": "success",
  "amount": 100.50,
  "currency": "USD",
  "timestamp": 1708123456
}

Note: The timestamp is the same as the first request!

Request Mismatch (Different Body, Same Key)
curl -X POST http://localhost:8080/payment \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: payment-001' \
  -d '{"amount":200.00,"currency":"EUR"}'

Response:

{
  "error": "request with same idempotency key has different content"
}

Status Code: 422 Unprocessable Entity

Features Demonstrated

  • ✅ Request deduplication
  • ✅ Response caching
  • ✅ Request validation (body mismatch detection)
  • ✅ In-memory storage
  • ✅ Multiple endpoints with idempotency

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL