Last active
June 9, 2020 19:04
-
-
Save VanDavv/b8c504fb709bb23eef50c4efe5d8d9ee to your computer and use it in GitHub Desktop.
simple flask api for counting people
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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