0
0
FastAPIframework~10 mins

Startup and shutdown events in FastAPI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to register a startup event handler in FastAPI.

FastAPI
from fastapi import FastAPI
app = FastAPI()

@app.[1]()
async def startup_event():
    print("App is starting")
Drag options to blanks, or click blank then click option'
Aon_startup
Bon_start
Cstartup
Dstart_event
Attempts:
3 left
💡 Hint
Common Mistakes
Using @app.startup() instead of @app.on_startup()
Misspelling the decorator name
2fill in blank
medium

Complete the code to register a shutdown event handler in FastAPI.

FastAPI
from fastapi import FastAPI
app = FastAPI()

@app.[1]()
async def shutdown_event():
    print("App is shutting down")
Drag options to blanks, or click blank then click option'
Aon_shutdown
Bshutdown
Con_stop
Dstop_event
Attempts:
3 left
💡 Hint
Common Mistakes
Using @app.shutdown() instead of @app.on_shutdown()
Misspelling the decorator name
3fill in blank
hard

Fix the error in the code to properly register a startup event handler.

FastAPI
from fastapi import FastAPI
app = FastAPI()

@app.[1]
async def startup_event():
    print("Starting app")
Drag options to blanks, or click blank then click option'
Astartup()
Bon_startup
Con_startup()
Dstartup
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting parentheses after the decorator name
Using incorrect decorator names
4fill in blank
hard

Fill both blanks to create a FastAPI app with startup and shutdown event handlers.

FastAPI
from fastapi import FastAPI
app = FastAPI()

@app.[1]()
async def startup_event():
    print("Starting app")

@app.[2]()
async def shutdown_event():
    print("Shutting down app")
Drag options to blanks, or click blank then click option'
Aon_startup
Bstartup
Con_shutdown
Dshutdown
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up startup and shutdown decorator names
Omitting parentheses after decorators
5fill in blank
hard

Fill all three blanks to create a FastAPI app that prints messages on startup and shutdown, and runs a main route.

FastAPI
from fastapi import FastAPI
app = FastAPI()

@app.[1]()
async def startup_event():
    print("App starting")

@app.[2]()
async def shutdown_event():
    print("App shutting down")

@app.get("/[3]")
async def read_root():
    return {"message": "Hello World"}
Drag options to blanks, or click blank then click option'
Aon_startup
Bon_shutdown
Dhome
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving the route path blank
Using incorrect decorator names
Omitting parentheses after decorators