A complete REST API example

In this recipe, we will convert the API structure created in the previous recipe, Creating a SQLAlchemy-independent REST API, into a full-fledged RESTful API interface.

Getting ready

We will take the API skeleton from the previous recipe as the base to create a complete functional SQLAlchemy-independent RESTful API. Although we will use SQLAlchemy as the ORM for demonstration, this recipe can be written in a similar fashion for any ORM or underlying database.

How to do it…

The following lines of code are the complete RESTful API for the Product model. These code snippets will go into the views.py file:

from flask.ext.restful import reqparse parser = reqparse.RequestParser() parser.add_argument('name', type=str) parser.add_argument('price', ...

Get Flask Framework Cookbook 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.