-
Book Overview & Buying
-
Table Of Contents
Building Python Microservices with FastAPI
By :
There are FastAPI components that are inherently asynchronous and one of them is the middleware. It is an asynchronous function that acts as a filter for the REST API services. It filters out the incoming request to pursue validation, authentication, logging, background processing, or content generation from the cookies, headers, request parameters, query parameters, form data, or authentication details of the request body before it reaches the API service method. Equally, it takes the outgoing response body to pursue rendition change, response header updates and additions, and other kinds of transformation that could possibly be applied to the response before it reaches the client. Middleware should be implemented at the project level and can even be part of main.py:
@app.middleware("http")
async def log_transaction_filter(request: Request,
call_next...