API Development

Path Parameters

API Development / Path Parameters

Path Parameters

FastAPI - Path Parameters

Modern web frameworks use routes or endpoints as a part of URL instead of file-based URLs. This helps the user to remember the application URLs more effectively. In FastAPI, it is termed a path. A path or route is the part of the URL trailing after the first /.

For example, in the following URL,

http://localhost:8000/hello/TutorialsPoint

the path or the route would be

/hello/TutorialsPoint

In FastAPI, such a path string is given as a parameter to the operation decorator. The operation here refers to the HTTP verb used by the browser to send the data. These operations include GET, PUT, etc. The operation decorator (for example, @app.get("/")) is immediately followed by a function that is executed when the specified URL is visited. In the below example −

from fastapi import FastAPI app = FastAPI() @app.get("/") async def index():   return {"message": "Hello World"}

Here, ("/") is the path, get is the operation, @app.get("/") is the path operation decorator, and the index() function just below it is termed as path operation function.

Technology
API Development
want to connect with us ?
Contact Us