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 simple GET route that returns a greeting.
@app.[1]("/") async def read_root(): return {"message": "Hello World"}
The @app.get decorator defines a GET HTTP method route.
Fix the error in the code to correctly include a router from another module.
from fastapi import FastAPI from routers import users app = FastAPI() app.[1](users.router)
add_route which is not a FastAPI methodmount with include_routerUse include_router to add routers from other modules in FastAPI.
Fill both blanks to create a modular project structure with routers and models.
from fastapi import FastAPI from [1] import router as user_router from [2] import User app = FastAPI() app.include_router(user_router)
Routers are usually in a routers folder, models in a models folder.
Fill all three blanks to define a Pydantic model and use it in a POST route.
from fastapi import FastAPI from pydantic import BaseModel class [1](BaseModel): name: str age: int app = FastAPI() @app.post("/users") async def create_user(user: [2]): return {"user_name": user.[3]
The Pydantic model is named User. The POST route accepts a User object and returns the name attribute.
