https://github.com/enthought/flask-apiblueprint
Default Repo description from terraform module
https://github.com/enthought/flask-apiblueprint
Last synced: 10 months ago
JSON representation
Default Repo description from terraform module
- Host: GitHub
- URL: https://github.com/enthought/flask-apiblueprint
- Owner: enthought
- License: other
- Created: 2016-09-20T10:28:42.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-09-20T20:57:59.000Z (almost 10 years ago)
- Last Synced: 2025-05-17T01:09:55.808Z (about 1 year ago)
- Language: Python
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Flask-APIBlueprint
==================
What is Flask-APIBlueprint?
-------------------------
Flask-APIBlueprint is a Flask micro-framework extension which adds support for
route inheritance for Blueprints.
If you're building an API with Blueprints in Flask, you don't have to redeclare the routes if using the `APIBlueprint` class. You can also override routes as you version your API and remap endpoints.
#### What do I need?
Flask. It will automatically be installed if you install the extension via pip:
```
$ pip install flask-apiblueprint
```
#### Where are the tests?
To run the tests use the `test_apiblueprint.py` file:
```
$ python test_apiblueprint.py
```
#### How do I implement this?
##### Inheritance
Use the `inherit_from` keyword argument in the `APIBlueprint` constructor to copy routes over from another `APIBlueprint`.
```
api_v2 = APIBlueprint(
'api_v2', __name__, subdomain='', url_prefix='/api/v2', inherit_from=api_v1
)
```
##### Override routes
To override copied routes, just redeclare them.
```
@api_v1.route('/user//')
def username(user_id):
username = User.query.get(user_id).username
return jsonify(username=username)
@api_v2.route('/user//')
def user_info(user_id):
username = User.query.get(user_id).username
firstname = User.query.get(user_id).firstname
return jsonify(data=dict(username=username, firstname=firstname))
```
##### Remap endpoints
Use the `remapping` keyword argument in the constructor to change the endpoints of inherited routes.
```
remapping = {'/users/list/': '/users/'}
api_v2 = APIBlueprint(
'api_v2', __name__, subdomain='', url_prefix='/api/v2', inherit_from=api_v1,
remapping=remapping
)
```
See the [docs](http://flask-apiblueprint.readthedocs.org/en/latest/) for more details or run the `app.py` file to see how the [sample_api](sample_api) is implemented.
```
$ python app.py
```