0
0
FastAPIframework~10 mins

Folder structure patterns 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 import the FastAPI class from the correct module.

FastAPI
from [1] import FastAPI
app = FastAPI()
Drag options to blanks, or click blank then click option'
Adjango
Bflask
Cfastapi
Drequests
Attempts:
3 left
💡 Hint
Common Mistakes
Importing FastAPI from Flask or Django modules.
2fill in blank
medium

Complete the code to define a route handler function for the root path.

FastAPI
@app.[1]("/")
async def read_root():
    return {"message": "Hello World"}
Drag options to blanks, or click blank then click option'
Aget
Bpost
Cput
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST or PUT instead of GET for a simple fetch route.
3fill in blank
hard

Fix the error in the import statement to correctly import the router from the users module.

FastAPI
from app.[1] import router

app.include_router(router)
Drag options to blanks, or click blank then click option'
Amodels
Bmain
Cschemas
Dusers
Attempts:
3 left
💡 Hint
Common Mistakes
Importing router from models or schemas instead of users.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps filenames to their sizes for files in the 'static' folder.

FastAPI
file_sizes = {file: [1] for file in os.listdir('static') if os.path.[2]('static/' + file)}
Drag options to blanks, or click blank then click option'
Aos.path.getsize('static/' + file)
Bos.path.isdir
Cos.path.isfile
Dos.path.exists
Attempts:
3 left
💡 Hint
Common Mistakes
Using os.path.isdir which checks for directories, not files.
5fill in blank
hard

Fill all three blanks to create a FastAPI app that includes a router and sets a title in metadata.

FastAPI
from fastapi import FastAPI
from app.[1] import router

app = FastAPI(title=[2])
app.[3](router)
Drag options to blanks, or click blank then click option'
Aitems
B"My FastAPI App"
Cinclude_router
Dusers
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the title string.
Using wrong method to add router.