Вы можете попробовать это,
from application import app
url_list = [
{'path': route.path, 'name': route.name}
for route in app.routes
]
здесь app
- это экземпляр класса FastAPI
.
Полный пример:
from fastapi import FastAPI
app = FastAPI()
@app.get(path='/', name='API Foo')
def foo():
return {'message': 'this is API Foo'}
@app.post(path='/bar', name='API Bar')
def bar():
return {'message': 'this is API Bar'}
@app.get('/url-list')
def get_all_urls():
url_list = [
{'path': route.path, 'name': route.name}
for route in app.routes
]
return url_list