
Fast_api Urls
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def get_product():
return "Hello World"
From this code the third line is a FastAPI path operation decorator.
when we run the command : uvicorn main:app --reload
it displays like this

if you observe the address bar after the ip address there is “/” and in the above code line number three we can observer this ("/") yes, these are related and knowns as path.
A URL is used by the client to locate and access a particular resource or API endpoint on the server. In FastAPI, the URL path is mapped to a path operation, such as a function, which handles the client's request.
FastAPI matches GET + / to get_product() and returns "Hello World".
class product(BaseModel):
Here
@app.get("/product") is an FastAPI path operation decorator . This contains @ is an decoarator syntax ,a decorator in python is way of modifing or add behaviour to a function without actual changing of the code.
app →FastAPI application object
.get→ Specifies http method
“/product”→ is an path
FastAPI's path operation decorator registers a path and HTTP method with a Python function. When a request arrives, FastAPI's routing system matches the request's HTTP method and URL path to the registered function and executes it.
Join Techsnap Creators
Share your knowledge and earn ??
Want to showcase your tech expertise and get rewarded for your insights? Join the Techsnap creator network!
Write insightful blogs, stay ahead of industry trends, and grow your professional brand while helping others in the community.
Ready to make an impact?

Comments