У нас вы можете посмотреть бесплатно Create custom middleware with FastAPI или скачать в максимальном доступном качестве, которое было загружено на ютуб. Для скачивания выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
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!