Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃摑 Add annotations to HTTP middleware example #11530

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Kilo59
Copy link

@Kilo59 Kilo59 commented May 4, 2024

Update documentation example for HTTP middleware to complete type annotations in the signature.

import time
from typing import Awaitable, Callable

from fastapi import FastAPI, Request, Response

app = FastAPI()


@app.middleware("http")
async def add_process_time_header(
    request: Request, call_next: Callable[[Request], Awaitable[Response]]
) -> Response:
    start_time = time.time()
    response = await call_next(request)
    process_time = time.time() - start_time
    response.headers["X-Process-Time"] = str(process_time)
    return response

@Kilo59 Kilo59 marked this pull request as ready for review May 4, 2024 01:30
@alejsdev alejsdev added the docs Documentation about how to use FastAPI label May 4, 2024
@alejsdev alejsdev changed the title Add annotations to HTTP middleware example 馃摑 Add annotations to HTTP middleware example May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation about how to use FastAPI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants