Complete the code to import the FastAPI class.
from fastapi import [1] app = [1]()
The FastAPI class is imported to create the app instance.
Complete the code to define a Pydantic model for user input validation.
from pydantic import BaseModel class User([1]): name: str age: int
Pydantic models inherit from BaseModel to enable validation.
Fix the error in the route decorator to accept POST requests.
@app.[1]("/users") async def create_user(user: User): return user
The POST method is used to send data to the server for creation.
Fill both blanks to validate user input and return a success message.
from fastapi import [1] @app.post("/users") async def create_user(user: [2]): return {"message": f"User {user.name} created"}
FastAPI is imported to create the app, and User is the Pydantic model for validation.
Fill all three blanks to create a validated POST endpoint that returns the user's age doubled.
from fastapi import [1] from pydantic import BaseModel app = [2]() class User(BaseModel): name: str age: int @app.post("/double-age") async def double_age(user: [3]): return {"double_age": user.age * 2}
FastAPI is imported and used to create the app instance. The User model validates input.
