Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

FastAPI - Dynamic response

  • datetime

  • A small step ahead generating part of the content of the response dynamically.

from fastapi import FastAPI
import datetime

app = FastAPI()


@app.get("/")
async def root():
    return {"message": f"Hello World at {datetime.datetime.now()}"}