FastAPI demo is a minimal implementation of a full-featured FastAPI instance.
FastAPI:
While there is a project generator that Tiangolo provided, it included more than just the basics. There is also a very helpful tutorial, but that is a piecemeal approach.
This project occupies the space between the tutorial and the project generator and is a quickstart for your API. There is just enough code to securely control access using JWT and OAuth2, persist data to a production-ready database (PostgreSQL), and conduct unit testing. There should be sufficient code to understand how to combine the elements of the tutorial, but not an overwhelming amount.
Download and follow instructions
Download and follow instructions
Download and follow instructions
- Install pipenv
pip install pipenv
- Use pipenv to create virtual environment and install dependencies
pipenv install
- Launch the virtual environment
pipenv shell
- Generate configuration files
python generate_config.py
- Launch a pgAdmin window
- Create a user
- Name: fastapi_demo
- Password: look in configuration/database.cfg and use the POSTGRES_PW value
- Privileges: Can Login
- Create a database
- Name: fastapi_demo
- Owner: fastapi_demo
- Security:
- Grantee: fastapi_demo
- Privileges: ALL (without grant option)
- Create a separate server instance in pgAdmin
- Use the fastapi_demo user and password to create a new "server" item in pgAdmin
- This makes sure that the database admin window will generate the exactly the same errors and won't create things that can't be accessed.
- Add the initial user
- Update the configuration/initial_user.cfg file as needed
python create_initial_user.py
- Launch the server
uvicorn main:app --reload
- Connect
- Browse to http://127.0.0.1:8000/docs
You should maintain the testing code as you build out your API. Running the current tests is done by calling:
python run_tests.py
All of the existing endpoints have tests written for them. The unittest framework is relatively easy and the examples are data-driven, so they should be easy to read.