
This course includes our updated coding exercises so you can practice your skills as you learn.
See a demo
Explore building a FastAPI full stack blog app with CRUD endpoints, authentication and authorization, user registration and sign-in, RESTful design, and unit tests.
Understanding the course structure and setting up our system.
Explore the course technology stack, including fast API for APIs and web apps, uvicorn asynchronous server, git and github, pytest with coverage, SQLAlchemy, postgres or sqlite, and jinja2 templates.
create a project directory and set up a virtual environment to isolate dependencies, activate it across platforms, and initialize git with a .gitignore to protect secrets.
Set up a backend with fastapi to build a hello world api, install requirements.txt, and run with uvicorn for live reload, then view the open api docs at /docs.
Master the core http verbs for create, read, update, delete: get to retrieve data, post to create records, put for full updates, patch for partial updates, delete to remove records.
Refactor project configuration variables by centralizing them in a settings class inside a code/config module. Manage environment-specific values for title and version across staging and production, and verify with uvicorn.
Create a GitHub repository and push your FastAPI project using git: initialize, add, commit, rename to main, add origin, and push, with a readme to guide collaboration.
Learn the FastAPI prerequisites and foundational topics, including type hinting, static type checking, advanced type hinting, iterators and generators for memory management, pedantic data validation, dependency injection, and asynchronous programming.
Explore how type hints in Python boost IDE autocompletion, readability, and bug prevention in production-grade projects, with examples using a total price function and the mypy static type checker.
Explore intermediate to advanced Python type hints, from lists, tuples, and dictionaries to unions and custom types. Learn modern typing with Python 3.9 and 3.10, including callable annotations and decorators.
Explore how iterators and generators improve memory efficiency by delivering one item at a time, and learn to use yield for scalable processing and fast api database sessions.
Explore inheritance and multiple inheritance in Python with Pydantic models for data validation in FastAPI, and grasp method resolution order and mixins.
Learn to use Pydantic for robust data validation in FastAPI apps, leveraging type hints, optional fields, enums, default factories, and custom validators, with nested models.
Use Pydantic validators to enforce field rules, such as raising a value error when emails contain the keyword admin. Apply a root validator to ensure password and confirm password match.
Demonstrate dependency injection in fastapi with a practical API that injects blog titles and user data into routes using function-based and parameterized dependencies.
Leverage dependency injection to override dependencies in tests, swapping in a dedicated testing database to keep the development db clean while validating unit tests for FastAPI routes.
Explore asynchronous programming in Python by contrasting synchronous and asynchronous approaches, illustrating how an event loop and IO-bound tasks optimize cpu idle time and improve network, database, and smtp interactions.
Connect to Postgres and SQLite databases, create the user and block tables, and establish a single database session for querying. Hash passwords to securely store user data.
Connect to the database using PostgreSQL with SQLAlchemy and psycopg2. Configure environment secrets with a dot env file and python-dotenv; assemble database url from host, port, user, password, and db.
Configure a FastAPI app to connect to a Postgres database with a SQLAlchemy engine and session, auto-create tables on startup, and manage database users and credentials.
Connect to SQLite by updating SQLAlchemy database URL and engine with connect_args to set check_same_thread to false, verify the database file appears, and prepare for Alembic migrations and model creation.
Set up Alembic for database migrations in a FastAPI project and manage schema changes with auto-generated revisions. Configure alembic.ini and env.py, connect to PostgreSQL, and protect credentials from GitHub.
Create blog and user models with SQLAlchemy, including id, title, seo-friendly slug, content, author_id foreign key to user, relationship to user, is_active, and created_at. Apply migrations with Alembic upgrade head.
Create a Pydantic user create schema that validates email and password before storage, using pedantic for email validation, and shows models reflect input/output rather than database structures.
Learn to use dependency injection to obtain a database session via a generator, yielding a single session and querying the user table to fetch records.
Understand why encryption isn't enough and how hashing securely stores passwords as a one-way process, verified by comparing hashes with bcrypt.
Implement password hashing with bcrypt by creating a hasher class using a password context, providing static methods to get password hash and verify passwords, and test with sample inputs.
Build routers for blogs and users, implement create, read, update, and delete operations, and apply rest api design principles in section 3 intro of FastAPI full stack web development course.
Build a FastAPI route to create new users, hash passwords, and return the created user. Organize code with API routers, versioned routes, and a repository to interact with the database.
Use a response model with orm_mode to expose id and email, hide hashed password, and return 201 created for user creation.
Create a FastAPI blog endpoint by validating input with a create blog schema, auto-generating a slug from the title, and storing the blog via a router and repository.
Learn how to create a fastapi get route to fetch a blog by id under the blocks path, returning title, content, and created date with a 404 when not found.
Fetches a list of active blogs by filtering is_active to true and returns the results as a list of blogs via a FastAPI router endpoint using a database session.
Build a blog update route with an inherited update schema from create blog, a put router at blogs/{id}, a response model, and repository logic to update title, content, and slug.
implement delete blog by id in a fastapi app by querying the blog, validating author, deleting from the database, committing, and returning success or error messages.
Define unit testing principles: fast, isolated, repeatable, self validating, and timely. Automate tests with docker compose and a ci/cd pipeline to run on every commit.
Configure pytest with fixtures and a sqlite test database, and write a first unit test for the FastAPI /users endpoint using a test client, expecting 201.
Learn how json web tokens enable authentication by signing a token with a secret key, including header, payload, and signature, and validating expiry without storing session data on the backend.
Create JWT tokens to power authentication in a FastAPI full stack app with Python, configuring a secret key, 30-minute expiry, and payload encoding via jwt.encode.
Implement authentication with JSON web token by validating email and password submitted as form data, retrieving the user by email, verifying the password, and returning a bearer access token.
Learn to enforce blog authorization in FastAPI with OAuth2 and JWT, validating the current user and ensuring only the post's author can update or delete.
Extend the project by building a blog web application that reads blogs from the crud api endpoints, aiming to resemble a medium-like reading experience.
Learn to serve HTML with FastAPI by integrating the Jinja2 templating engine. Configure templates, a base layout with template inheritance, and render dynamic content with home.html.
Create a shared navbar as a template resource and include it in base.html so it appears on all pages, with the request passed to templates for cookies and user data.
Serve static assets with FastAPI by mounting a static directory for images, css, and js files. Configure StaticFiles and organize assets in a static folder to load a logo.
Create a blog list view by fetching active blocks with a repository pattern, passing them to templates, and rendering cards with title, formatted date, truncated content, and a detail view.
Demonstrates building a blog detail view in a FastAPI app by retrieving a blog by id using a db session and rendering it with a detail.html template.
Register users by serving a registration form and handling post data in FastAPI. Validate email and password, create the user, and redirect home with an alert.
Enable login in a FastAPI web app by rendering a login form, authenticating the user, issuing a bearer access token, storing it in a cookie, and redirecting to home.
This course is a guide to learn FastAPI. The FastAPI documentation is one of the best documentation. This course is for students who love videos as a medium to learn. We will be learning FastAPI with best practices. The Test-Driven Development goat ? will guide our development process. TDD is the way to think of the code before we actually write a piece of code. In this course we will be learning the following core concepts:
Creating APIs : We will implement the below endpoints:
Create
Retrieve
Update
Delete
List Blogs
User Authentication with basic security
Password will be hashed to provide additional security
We will use JSON Web Tokens to authenticate
Tokens won't be stored in LocalStorage or Cookies
Token will be stored in HttpOnly cookie
Version Control System
We will use GIT as our Version Control
Github will be used to host our code
Creating web apps
We will use Jinja Templating Language
We will be working with several forms
Unit Testing
Tests will be written in Pytest
After each testing cycle, the Test database will be cleaned
Test Coverage
How not to write unit tests?
Permissions: A user who has not created the blog, won't be able to delete it.
We will work with Postgres and monitor it using PgAdmin.
Fastapi provides us with built-in OpenAPI docs, we will use the documentation to the fullest. The docs help backend and frontend developers collaborate easily with each other.