Automatically generate data APIs for your Flask routes
Project description
Automatically generate data APIs for your Flask routes, with very little effort on your part. It should integrate into your existing application with very few changes required.
Usage
Given the following code:
from flask import Flask app = Flask(__name__) @app.route('/foo') def foo(): return render_template('foo.html', foo='bar', baz='boo')
We can automatically generate API functions for this route, rather simply:
from flask import Flask from flask_dataapi import DataApi app = Flask(__name__) api = DataApi(app) @api.route('/foo') def foo(render_template): return render_template('foo.html', foo='bar', baz='boo')
There are only two changes made. First, we call api.route for the decorator, and second, the first argument to the view function is the render_template function that we’ll call.
This will automatically add a second route of /foo.json that outputs JSON of the data that was provided to render_template. The route will have a name of foo_api, so links or other references will use that name, e.g. url_for('foo_api').
Motivation
In addition to free code, we also need free data. This makes it trivial to ensure that all data presented to users is easily extractable by the user.
License
flask-dataapi is available under the terms of the AGPL, version 3 or any later version.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for flask_dataapi-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed9181ea90556e5282db2a53c9b7a2832c8b30ccd0c9f3fba2fa82237b6b1526 |
|
MD5 | 3057682c71f0ab6b9cf5ea0e03fcd183 |
|
BLAKE2b-256 | fc7f9a2ced425acad41af242ab9b9a202997125843a15b10c934948d49b2fc2b |