Skip to content

Instantly share code, notes, and snippets.

@joeclark-phd
Created September 18, 2015 05:39
Show Gist options
  • Save joeclark-phd/1c2e56af8b7a2a01e3a4 to your computer and use it in GitHub Desktop.
Save joeclark-phd/1c2e56af8b7a2a01e3a4 to your computer and use it in GitHub Desktop.
quick JSON api mockup with flask that works on heroku
import os
from flask import Flask, jsonify
app = Flask(__name__)
# listing all items
@app.route("/api/items", methods=['GET'])
def list_items():
fake_data = { "items": [ {"name":"Widget","id":42,"price":49.95},
{"name":"Doodad","id":43,"price":19.95},
{"name":"Gizmo","id":44,"price":99.95} ]
}
return( jsonify(fake_data) )
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment