0
0
FastAPIframework~10 mins

Async vs sync decision in FastAPI - Interactive Practice

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

Complete the code to define a synchronous FastAPI route handler.

FastAPI
from fastapi import FastAPI
app = FastAPI()

@app.get("/sync")
def [1]():
    return {"message": "Hello from sync"}
Drag options to blanks, or click blank then click option'
Aasync_handler
Bsync_handler
Chandle_async
Dasync_func
Attempts:
3 left
💡 Hint
Common Mistakes
Using async def for a synchronous route
Naming the function with async prefix when it's sync
2fill in blank
medium

Complete the code to define an asynchronous FastAPI route handler.

FastAPI
from fastapi import FastAPI
app = FastAPI()

@app.get("/async")
async def [1]():
    return {"message": "Hello from async"}
Drag options to blanks, or click blank then click option'
Ahandle_sync
Bsync_handler
Casync_handler
Dsync_func
Attempts:
3 left
💡 Hint
Common Mistakes
Using def instead of async def for async routes
Naming the function with sync prefix when it's async
3fill in blank
hard

Fix the error in the async route handler by completing the code.

FastAPI
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"}
Drag options to blanks, or click blank then click option'
Adata_fetch
Bget_data
Cfetch
Dfetch_data
Attempts:
3 left
💡 Hint
Common Mistakes
Awaiting a non-async function
Calling a function that does not exist
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that filters async results.

FastAPI
results = {item: value for item, value in data.items() if value [1] 10 and item.startswith([2])}
Drag options to blanks, or click blank then click option'
A>
B"a"
C<
D"z"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operator
Forgetting quotes around string literals
5fill in blank
hard

Fill all three blanks to create an async function that fetches and filters data.

FastAPI
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
Drag options to blanks, or click blank then click option'
Afetch_data
B>
Cstartswith
Dget_data
Attempts:
3 left
💡 Hint
Common Mistakes
Not awaiting the async function
Using wrong operators or methods in filtering