Skip to content

Microservices built with FastAPI over Northwind database ported to PostgreSQL and deployed by Docker Swarm. Payments via PayPal sandbox. Sample metrics setup with cAdvisor, Prometheus and Grafana.

License

Notifications You must be signed in to change notification settings

adniec/fastapi-over-northwind

Repository files navigation

FastAPI over Northwind PostgreSQL Database

Diagram

About

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):

make_order

Build

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

Services

Endpoints

products

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.

Authorization

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.

Tests

Animation shows manual tests performed through Swagger UI:

errors

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

tests

License

This project is under the Ms-PL License

About

Microservices built with FastAPI over Northwind database ported to PostgreSQL and deployed by Docker Swarm. Payments via PayPal sandbox. Sample metrics setup with cAdvisor, Prometheus and Grafana.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published