Inspired by stripe's idempotent endpoints.
pip install flask-once
import uuid
from flask import Flask
from flask import jsonify
import flask_once
from flask_once import idempotent
app = Flask(__name__)
#: cache supports dict interface
app.cache = dict()
flask_once.attach(app, app.cache)
@app.route("/endpoint", methods=["POST"])
@idempotent()
def create_transaction():
uuid = str(uuid.uuid4())
return jsonify(transaction=uuid)
pip install requirements-dev.txt
make test
Start app
python example.py
Curl endpoints
curl localhost:5000/endpoint \
-H 'Idempotent-Key: x'
make tag
- Only cache routes with decorator.
- Add tests endpoints not wrapped in idempotency