Hands-on examples exploring FastAPI fundamentals and common authentication patterns. Each folder is a self-contained mini-project you can run independently.
simple-fastAPI-app/: Core FastAPI concepts (paths, query/body params, basic CRUD helpers).random-joke-using-template/: Server-side rendering with templates and a simple authenticated route.authentication-techniques/: Three auth approaches with runnable examples:basic-auth/– HTTP Basic Auth with password hashingsession-based/– Cookie sessions backed by a server storejwt/– OAuth2 password flow issuing JWT bearer tokens
- Python 3.10+
- Recommended: a virtual environment (e.g.,
python -m venv .venv)
Clone and enter the repository:
git clone https://github.com/<your-username>/A-FastAPI-Journey.git
cd A-FastAPI-JourneyEach example lists its own dependencies. Change into a module and install what it needs, then run the app.
cd simple-fastAPI-app
pip install fastapi[standard]
fastapi dev simplest_app.py
# or
uvicorn simplest_app:app --reload --host 0.0.0.0 --port 8000cd random-joke-using-template
pip install fastapi[standard]
fastapi dev main.pySee the overview and detailed docs:
authentication-techniques/README.mdauthentication-techniques/basic-auth/README.mdauthentication-techniques/session-based/README.mdauthentication-techniques/jwt/README.md
Quickstarts:
# Basic Auth
cd authentication-techniques/basic-auth
pip install fastapi[standard] passlib[bcrypt]
fastapi dev main.py
# Session-based
cd ../session-based
pip install fastapi[standard] fastapi-sessions
fastapi dev main.py
# JWT (token-based)
cd ../jwt
pip install fastapi[standard] passlib[bcrypt] PyJWT
fastapi dev main.pyFor any running app:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
A-FastAPI-Journey/
├── authentication-techniques/
│ ├── basic-auth/
│ ├── session-based/
│ └── jwt/
├── random-joke-using-template/
├── simple-fastAPI-app/
└── LICENSE
- Always use HTTPS in production.
- Store password hashes only (e.g., bcrypt), never plaintext.
- Keep secrets (session/JWT keys) in environment variables.
- For JWTs, use short expirations and consider refresh tokens.
- For sessions, mark cookies
Secure,HttpOnly, and setSameSite.
Issues and PRs are welcome. If you add a new example, include a minimal README.md and clear run instructions.
This project is licensed under the terms of the LICENSE file included in the repository.