A basic full-stack app using Python, apiflask and good ol' html.
- web framework: https://flask.palletsprojects.com/en/3.0.x/
- api docs: https://apiflask.com/usage/
- db: https://www.sqlite.org/
Note
Install python dependencies in a virtual sandbox to isolate any impacts to host system.
python -m venv .
- this will generate a
./bin
,./include
,./lib
and./pyvenv.cfg
in your chosen directory (.
in this case)
source bin/activate
to activate the virtual environmentpip install -r requirements.txt
to install all dependencies from./requirements.txt
python src/app.py
- head to
http://127.0.0.1:5000
for app (root/
is the web app)
Tip
Change local host above to any address of your choice by editing src/app.py
python src/app.py
- head to
http://127.0.0.1:5000/docs
for locally hosted OpenAPI spec (auto generated) - run
flask spec
to generate an OpenAPI 3.0 spec, which can be used to host elsewhere
Warning
not all routes contain the same level of information as apiflask was being explored
- in 1 process, start the server
python src/app.py
- in a 2nd process, run the tests
pytest tests/tests.py --html=./report.html
- assertion examples - https://naodeng.medium.com/pytest-tutorial-advance-usage-common-assertions-and-data-driven-e72122b9ec48
- run behind reverse proxy (https://apiflask.com/tips/)
- add configs to run different environments (dev, prod)
- add UI form to update books & wrap up PUT /book/{id} endpoint
- utilise db migrations
- introduce a Bookshelf table which contains Books (1 to many)
- dockerize the app
- https://github.com/apiflask/apiflask
- https://medium.com/@nileshshindeofficial/in-this-blog-well-explore-how-to-use-flask-with-sqlite-a-lightweight-and-easy-to-use-database-c302cd939a0f
- https://www.sqlitetutorial.net/sqlite-python/ https://auth0.com/blog/developing-restful-apis-with-python-and-flask/