Complete the code to define a synchronous FastAPI route handler.
from fastapi import FastAPI app = FastAPI() @app.get("/sync") def [1](): return {"message": "Hello from sync"}
The function is synchronous, so it should be a normal def function, here named sync_handler.
Complete the code to define an asynchronous FastAPI route handler.
from fastapi import FastAPI app = FastAPI() @app.get("/async") async def [1](): return {"message": "Hello from async"}
Asynchronous route handlers use async def, so the function name async_handler fits the async style.
Fix the error in the async route handler by completing the code.
from fastapi import FastAPI app = FastAPI() @app.get("/data") async def get_data(): data = await [1]() return data async def fetch_data(): return {"info": "sample"}
The await keyword must be used with an async function, here fetch_data().
Fill both blanks to create a dictionary comprehension that filters async results.
results = {item: value for item, value in data.items() if value [1] 10 and item.startswith([2])}The comprehension filters items with value greater than 10 and keys starting with "a".
Fill all three blanks to create an async function that fetches and filters data.
async def process_data(): raw = await [1]() filtered = {k: v for k, v in raw.items() if v [2] 5 and k.[3]("b")} return filtered
The async function awaits fetch_data(), then filters items with value greater than 5 and keys starting with "b".