Skip to content

Instantly share code, notes, and snippets.

@VanDavv
Last active June 9, 2020 19:04
Show Gist options
  • Save VanDavv/b8c504fb709bb23eef50c4efe5d8d9ee to your computer and use it in GitHub Desktop.
Save VanDavv/b8c504fb709bb23eef50c4efe5d8d9ee to your computer and use it in GitHub Desktop.
simple flask api for counting people
#!/usr/bin/env python3
from flask import Flask, jsonify, request
app = Flask(__name__)
people_count = 0
@app.route("/increase/", methods=['POST'])
def run():
global people_count
count = request.json.get("count", 1) if request.json is not None else 1
people_count += count
return jsonify(success=True)
@app.route("/decrease/", methods=['POST'])
def kill():
global people_count
count = request.json.get("count", 1) if request.json is not None else 1
people_count -= count
return jsonify(success=True)
@app.route("/count/", methods=['GET'])
def status():
global people_count
return jsonify(count=people_count)
app.run(host='0.0.0.0', port=8080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment