Last active
August 31, 2021 17:42
-
-
Save Kludex/c22817bbf17328b0900c506e580e42c6 to your computer and use it in GitHub Desktop.
Create dynamic endpoints in FastAPI - DO NOT USE THIS!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import string | |
from fastapi import FastAPI | |
from fastapi.openapi.utils import get_openapi | |
app = FastAPI() | |
def custom_openapi(): | |
return get_openapi(title=app.title, version=app.version, routes=app.routes) | |
app.openapi = custom_openapi | |
@app.get("/") | |
def randomize(): | |
path = "".join(random.choice(string.ascii_lowercase) for _ in range(5)) | |
app.add_api_route(path, lambda: None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment