Sample implementation of microservices created with FastAPI and run by Docker over Northwind database ported to PostgreSQL. Endpoints authorization through HTTP Basic. Payment mechanism via PayPal sandbox. Monitoring and alerting with:
Performance of operations direct on database versus through API is shown here.
Animation below illustrates making an order and not finalizing payment (changes to database are reversed after some time - shorter for example purpose):
To build project use Docker Swarm. Follow instructions below:
git clone https://github.com/ethru/fastapi-over-northwind.git
cd fastapi-over-northwind
docker stack deploy app -c docker-compose.yml
To see service documentation and test it go to http://0.0.0.0:8080/api/'service-name'/docs
in browser.
Note: during first run database is created and there can occur problem with connection from services listed below. If
502 Bad Gateway
shows up after going to services URLs restart them with:
docker service update --force app_categories_service
docker service update --force app_products_service
docker service update --force app_orders_service
docker service update --force app_reports_service
- http://0.0.0.0:8080/api/categories/docs
- http://0.0.0.0:8080/api/products/docs
- http://0.0.0.0:8080/api/orders/docs
- http://0.0.0.0:8080/api/reports/docs
Manual tests of services can be done in Swagger UI (see photo). To send DELETE
request click on it then press Try it out
button and Execute
. Result will appear below.
Some endpoints are protected with HTTP Basic
against unauthorized access. They are marked with grey locker on the
right side. To perform action log in first. Press Authorize
button or locker
icon and pass authorization header
into value field. It is created from username
and password
. Default: admin
and password
which give header Basic YWRtaW46cGFzc3dvcmQ=
. Feel free to modify linked files to your needs. Then generate header
using for example this tool.
Animation shows manual tests performed through Swagger UI:
Tests are located in tests directory. To run them install all dependencies first:
pip install pytest
pip install pytest-dependency
pip install pytest-ordering
Then build project. It is mandatory, because all tests are performed on live endpoints. When environment will be ready in main directory use command:
python -m pytest tests
This project is under the Ms-PL License