Complete the code to import FastAPI and create an app instance.
from fastapi import [1] app = [1]()
You need to import FastAPI and create an instance of it to start your app.
Complete the code to define a GET endpoint that returns a greeting.
@app.[1]("/") async def read_root(): return {"message": "Hello World"}
The decorator @app.get defines a GET HTTP method endpoint.
Fix the error in the code to correctly inject a dependency using Depends.
from fastapi import Depends def get_token(): return "token123" @app.get("/items") async def read_items(token: str = [1](get_token)): return {"token": token}
Use Depends to declare dependencies in FastAPI endpoints.
Fill both blanks to create a POST endpoint that accepts a Pydantic model and returns it.
from pydantic import BaseModel class Item(BaseModel): name: str price: float @app.[1]("/items") async def create_item(item: [2]): return item
Use @app.post to define a POST endpoint and use the Pydantic model Item as the parameter type.
Fill all three blanks to create a FastAPI app with a startup event and a simple GET endpoint.
from fastapi import [1] app = [2]() @app.[3]("/status") async def status(): return {"status": "ok"} @app.on_event("startup") async def startup_event(): print("App is starting")
Import FastAPI, create an app instance, and define a GET endpoint with @app.get.
