ycliper

Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
Скачать

Create custom middleware with FastAPI

fastapi

python

pythonprogramming

api

apis

rest

restful

rest apis

web middleware

middleware

web server

python programming

Автор: microapis

Загружено: 2024-06-04

Просмотров: 2613

Описание: Create custom middleware with FastAPI

The code for this tutorial is available on GitHub: https://github.com/abunuwas/short-tut...

What is middleware? Middleware is a layer that pre-processes requests in web servers. Before a request reaches our controllers, i.e. the functions that implement endpoints/URLs in our API, there's a pre-processing stage. In that stage, the framework parses the request, validates the headers, the content type, the data types, and so on.

Most web development frameworks allow us to create custom middleware, and this is incredibly useful to add custom pre-processing components. For example, we may want to check for custom headers in the request. We can also use middleware to handle authorization and authentication, to log requests, to implement rate-limiting/throttling policies, to track user interactions, and more.

We have two ways of creating custom middleware in FastAPI:

Decorator-based middleware

Class-based middleware

Decorator-based middleware has a simple and nice interface and it's very convenient for small and simple middleware components. Class-based middleware is suitable for complex components that need to be isolated and encapsulated into their own modules.

In this video, I show you how to create middleware in FastAPI using both approaches. We implement a very simple API, and then we add a simple middleware that checks whether requests have a custom header X-User-Type and its value. It's best practice to prefix customer headers with X- to easily tell them apart from standard headers.

In future videos, I'll show you how to create middleware for Flask and Django, and how to create more complex middleware.

Let me know what you liked and didn't like about this video, and what other topics you'd like me to cover!

If you want to learn to build production-grade APIs with FastAPI and SQLAlchemy, sign up for "Build APIs with Python". Use the coupon 30-OFF-340EF7ED to obtain a 30% discount: https://sso.teachable.com/secure/1592...


00:00 Introduction
02:30 Setting the environment (Poetry)
04:15 Creating server.py
04:48 Configuring the environment in the DE (Pycharm)
05:35 Creating a hello world endpoint
06:12 Running the API server
07:10 Project requirements
08:32 Types of middleware in FastAPI
08:52 Creating a decorator-based middleware
12:22 Testing the middleware
14:07 Implementing class-based middleware
17:50 Testing the class-based middleware
19:02: Wrapping up


If you liked this video, please like it and share it with your network, and subscribe to my channel!

I'm also the author of the following Manning books:

"Microservice APIs" (http://mng.bz/jy4x). Get a 40% discount using the following code: slperalta (reach out to me if you have issues using the code).

"Secure APIs" (https://mng.bz/4JVg). This book is currently available in early access, which means only the first few chapters are published and you'll get access to more as I progress in my writing. You also get a chance to give me feedback and help me improve the book. Get a 40% discount using the following code: watchperalta40 (reach out to me if you have issues using the code).

You can also download two chapters of the book for free from this link: https://microapis.io/resources/micros...

Check out my newsletter for advanced content on APIs and distributed systems: https://microapis.substack.com/

Let me know also what other kinds of topics you'd like me to address in future videos!

Не удается загрузить Youtube-плеер. Проверьте блокировку Youtube в вашей сети.
Повторяем попытку...
Create custom middleware with FastAPI

Поделиться в:

Доступные форматы для скачивания:

Скачать видео

  • Информация по загрузке:

Скачать аудио

Похожие видео

Middleware в FastAPI - разбираем на стриме c мемными кодами HTTP и атакующей собакой-облизакой

Middleware в FastAPI - разбираем на стриме c мемными кодами HTTP и атакующей собакой-облизакой

FastAPI полный курс от А до Я | Depends | Middleware | Background Tasks

FastAPI полный курс от А до Я | Depends | Middleware | Background Tasks

Build APIs with Flask (the right way)

Build APIs with Flask (the right way)

Nest.js — лучший бэкэнд фреймворк | Полный курс 2025

Nest.js — лучший бэкэнд фреймворк | Полный курс 2025

Learn Middleware by Building a REAL Project (fastapi rate limiting)

Learn Middleware by Building a REAL Project (fastapi rate limiting)

Git tutorial for beginners [2024]

Git tutorial for beginners [2024]

Performance tips by the FastAPI Expert — Marcelo Trylesinski

Performance tips by the FastAPI Expert — Marcelo Trylesinski

Dependency Injection Explained Like You’re 5 (with FastAPI Examples)

Dependency Injection Explained Like You’re 5 (with FastAPI Examples)

План развития backend разработчика

План развития backend разработчика

FastAPI with SQLAlchemy Tutorial

FastAPI with SQLAlchemy Tutorial

© 2025 ycliper. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]