Skip to content
Discussion options

You must be logged in to vote

Hi!
Path is a special function that helps to get the value from the request URL. Here it is used because this dependency is then applied to some other routes to get the article by slug. If you need to get the path from the URL after the host, then you can pass a request to the FastAPI route (or dependency). After that, you can take path from URL from starlette.requests.Request if this is what you need:

from fastapi import FastAPI
from starlette.requests import Request

app = FastAPI()

@app.get("/path")
async def my_route(request: Request) -> None:
    print(request.url.path)

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
3 participants
Converted from issue

This discussion was converted from issue #828 on February 28, 2023 11:10.