Skip to content

Instantly share code, notes, and snippets.

@Kludex
Last active August 31, 2021 17:42
Show Gist options
  • Save Kludex/c22817bbf17328b0900c506e580e42c6 to your computer and use it in GitHub Desktop.
Save Kludex/c22817bbf17328b0900c506e580e42c6 to your computer and use it in GitHub Desktop.
Create dynamic endpoints in FastAPI - DO NOT USE THIS!
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