Observe an awaited background task
FastAPI can attach work to a response with BackgroundTasks. The task runs after the response is sent by the application. An in-memory test client waits for that ASGI application call to complete, so the test can inspect the task's effect after awaiting the request.
This is an in-process task, not a durable job queue. Keep the demonstration effect in a list supplied by the test. An async task avoids thread-pool dispatch in the browser. Do not infer that a real remote HTTP caller waits for background work merely because the in-memory test observes its completion.
from fastapi import BackgroundTasks
seen = []
async def record(value):
seen.append(value)
tasks = BackgroundTasks()
tasks.add_task(record, "tea")
import asyncio
asyncio.run(tasks())
print(seen)Your task
Implement build_app(seen). POST /record/{value} accepts an int, returns {"queued":value}, and adds an async background task appending the value to the supplied list. Invalid paths must not append.
The explanation opens here once every check passes.