Last active
October 7, 2015 22:29
-
-
Save joeclark-phd/6b0e30e3d07e384072a9 to your computer and use it in GitHub Desktop.
app.py for Bluemix flinkedin-clark
This file contains 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
import os | |
from flask import Flask, jsonify | |
app = Flask(__name__) | |
@app.route("/", methods=['GET']) | |
def hello_world(): | |
return( "Hello world. Try /api/profiles or /api/companies for data." ) | |
# listing all profiles | |
@app.route("/api/profiles", methods=['GET']) | |
def list_profiles(): | |
fake_data = { "profiles": [ {"name":"John McLane","id":"jmclane"}, | |
{"name":"James Edwards","id":"j"}, | |
{"name":"Samwise Gamgee","id":"samgamgee"} ] | |
} | |
return( jsonify(fake_data) ) | |
# retrieve one profile | |
@app.route("/api/profile/<string:id>", methods=['GET']) | |
def one_profile(id): | |
fake_data = { "profile": {"name":"John McLane","id":id, | |
"jobs":[ | |
{"employer":"NYPD","position":"Lieutenant","start":1988} | |
]} } | |
return( jsonify(fake_data) ) | |
# listing all companies | |
@app.route("/api/companies", methods=['GET']) | |
def list_companies(): | |
fake_data = { "companies": [ {"name":"NYPD"}, | |
{"name":"MIB"}, | |
{"name":"Bag End"} ] | |
} | |
return( jsonify(fake_data) ) | |
# list all profiles for one company | |
@app.route("/api/company/<string:company>", methods=['GET']) | |
def one_company(company): | |
fake_data = { "company": company, | |
"profiles": [ {"name":"John McLane","id":"jmclane"}, | |
{"name":"James Edwards","id":"j"} ] | |
} | |
return( jsonify(fake_data) ) | |
if __name__ == "__main__": | |
port = int(os.environ.get("VCAP_APP_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