foxyblue / flask-once

Idempotent decorator for flask routes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flask-Once

Idempotent decorator for flask routes.

Inspired by stripe's idempotent endpoints.

Install

pip install flask-once

Usage

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)

Test

pip install requirements-dev.txt
make test

Run example

Start app

python example.py

Curl endpoints

curl localhost:5000/endpoint \
    -H 'Idempotent-Key: x'

Upload

make tag

TODO:

  • Only cache routes with decorator.
  • Add tests endpoints not wrapped in idempotency

About

Idempotent decorator for flask routes.


Languages

Language:Python 96.3%Language:Makefile 3.7%