This talk will show you how to create a really
simple Flask API application. Keep its source
code on Github and have wercker CI to
automatically deploy successful commits to
an OpenShift application
CODE on github: https://github.com/rochacbruno/flask-openshift-wercker
3. 1. Flask creating an API
2. Github and webhooks
3. OpenShift what is and how it works w/ Python
4. Wercker CI and deployment targets
4. Objective:
This talk will show you how to create a really
simple Flask API application. Keep its source
code on Github and have wercker CI to
automatically deploy successful commits to
an OpenShift application.
5. pip install -r requirements.txt
# The Flask Framework
flask
# A helper to run wsgi apps on OPenShift
shiftpy
# Test runner
pytest
pytest-flask
7. api.py
from flask import Flask, jsonify
api = Flask(__name__)
@api.route('/calc/<string:op>/<int:number>/<int:other>')
def calc(op, number, other):
operations = {"sum": lambda a, b: a + b,
"mul": lambda a, b: a * b,
"sub": lambda a, b: a - b,
"div": lambda a, b: a / b}
return jsonify({"result": operations[op](number, other)})
if __name__ == "__main__":
api.run(debug=True)