Skip to content

Instantly share code, notes, and snippets.

Created April 2, 2014 12:55
Show Gist options
  • Save anonymous/9933517 to your computer and use it in GitHub Desktop.
Save anonymous/9933517 to your computer and use it in GitHub Desktop.
from flask import Flask, jsonify, request
app = Flask(__name__)
shop = [
{
"id": 1,
"title": "Java",
"available": 8
},
{
"id": 2,
"title": "C++",
"available": 7
},
{
"id": 3,
"title": "Python",
"available": 6
}
]
@app.route("/products")
def list_products():
return jsonify( {"products:" : shop } )
@app.route("/invoice", methods = ["POST"] )
def buy():
id = request.json["id"]
for product in shop:
if product["id"] == id:
product["available"] = product["available"] - 1
return jsonify( { "status" : "OK" })
return jsonify( {"status" : "rejected" }), 400
if __name__ == '__main__':
app.run(debug = True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment