A CRUD API to practice Flask and Python, which I created before implementing the Full Fibre's technical test, in order to learn the patterns of documenting, implementing and testing a green-field Flask API and forge my own opinion about Flask and its ecosystem.
The Practice CRUD API uses Python 3.8.
# Virtual environment:
py -m venv .venv
./.venv/Scripts/Activate.ps1
# Installing project dependencies:
pip install -r requirements.txt
# You may also need:
pip install -e .
# Tests:
pytest
# Tests with coverage:
coverage run -m pytest ; coverage report
# Create the database schema:
flask create-db
# Start the development server:
$Env:FLASK_DEBUG = 1 ; flask run
# Fill the database with sample data:
flask fill-db
- https://flask.palletsprojects.com/en/2.0.x/
- https://flask-sqlalchemy.palletsprojects.com/en/2.x/
- https://marshmallow.readthedocs.io/en/stable/
- https://docs.sqlalchemy.org/en/14/orm/tutorial.html
- https://flask-restplus.readthedocs.io/en/stable/
- https://flask-restx.readthedocs.io/en/latest/
- https://flask-smorest.readthedocs.io/en/latest/
- https://github.com/tecladocode/rest-apis-flask-python
- https://www.mscharhag.com/api-design/rest-many-to-many-relations
- https://www.mscharhag.com/api-design/rest-one-to-many-relations
- https://github.com/lafrech/flask-smorest-sqlalchemy-example
- https://github.com/picsouds/flask-smorest-example-bookmanager
- And more...
- I'm still much confused about the Flask-RestFull / Flask-RestPlus / Flask-RestX / Flask-SmoRest struggle...
- There seems to be a part of the Flask API that isn't documented (e.g.
flask.views.MethodView
). - When adding new API resources, it's better to:
- Add it as an independent resource, i.e. without relations/FKs/links.
- Test the validation and other features for the basic resource.
- Commit.
- And only then add the relations to other API resources.