
Parameters to URL
Imagine going to a shopping mall. There are thousands of products, but you don't need all of them. You want a particular ice cream. So instead of looking through every product, you go directly to the ice-cream section and select the ice cream you want.
Similarly, in a shopping application, the server may have thousands of products. If the client wants a particular product, we need a way to identify and retrieve it. Path parameters and query parameters help the client provide this information through the URL.
In python we define a function with parameters
example
def get_product(product_id):
return product_id
when we call it we provide an argument,here 10 is the argument passed to the function.
A similar idea exists in API URLs. The client can provide values through the URL
Path Parameter
A path parameter is a dynamic value passed directly inside the url path,usally used to identify a specific resource.
example:-
class product(BaseModel):
Here the the parameter "id" can considered as path parameter

Query Parameter:-
A query parameter is a key-value pair added to the URL after ? commonly used to provide additional options such as filtering,searching,pagination and other optional information
class product(BaseModel):
@app.get("/product")
@app.post("/product")

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