Installing Flask-Restless
With our model in place, we are now ready to install Flask-Restless, a third-party Flask extension that makes it simple to build RESTful APIs for your SQLAlchemy models. After ensuring that you have activated the blog app's virtual environment, install Flask-Restless using pip
:
(blog) $ pip install Flask-Restless
You can verify if the extension is installed by opening up the interactive interpreter and getting the version that is installed. Don't forget, your exact version number may differ.
(blog) $ ./manage.py shell In [1]: import flask_restless In [2]: flask_restless.__version__ Out[2]: '0.13.0'
Now that we have Flask-Restless installed, let's configure it to work with our application.
Setting up Flask-Restless
Like other Flask extensions, we will begin in the app.py
module by configuring an object that will manage our new API. In Flask-Restless, this object is called an APIManager
and it will allow us to create RESTful endpoints for our SQLAlchemy models. Add...