Simple APIs with Flask-RESTful
One of the great joys of using Flask is the seemingly infinite extensibility and composability that it offers. As it's a rather thin layer that sits atop Werkzeug and Jinja, it does not impose much on the developer in terms of constraints.
Due to this flexibility, we have extensions such as Flask-RESTful at our disposal, which make creating JSON-based APIs a joy. First, let's install the package:
$ pip install flask-restful
Next, let's initialize the extension in our application factory in the usual fashion:
from flask import Flask from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.bcrypt import Bcrypt from flask.ext.restful import Api # ……… api = Api() def create_app(config=None): app = Flask(__name__) if ...
Get Flask Blueprints now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.