Map multiple api endpoints to a single path operation function #6673
-
|
Is there a way to map multiple api endpoints to a single path operation function? For example, if I make a get request "/get-employees" or "/employees", can they both map to the same path operation function like below? Examplefrom fastapi import FastAPI
app = FastAPI()
@app.get(["/get-employees", "/employees"])
def read_root():
return {"Hello": "World"} |
Beta Was this translation helpful? Give feedback.
Answered by
stlucasgarcia
Jun 7, 2021
Replies: 2 comments
-
|
You need to create two separate decorators: from fastapi import FastAPI
app = FastAPI()
@app.get("/get-employees")
@app.get("/employees")
def read_root():
return {"Hello": "World"} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
YuriiMotov
-
|
Thank you |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to create two separate decorators: