http-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

HTTP Basic Example

This example demonstrates basic idempotency handling with standard net/http using in-memory storage.

Running the Example

cd examples/http-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":250.00,"currency":"EUR"}'

Response:

{
  "status": "success",
  "amount": 250.00,
  "currency": "EUR",
  "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":250.00,"currency":"EUR"}'

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

{
  "status": "success",
  "amount": 250.00,
  "currency": "EUR",
  "timestamp": 1708123456
}

Note: The timestamp is identical to the first request!

Features Demonstrated

  • ✅ Standard library HTTP middleware
  • ✅ Request deduplication
  • ✅ Response caching
  • ✅ In-memory storage

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