Complete the code to import the correct FastAPI class.
from fastapi import [1] app = FastAPI()
The FastAPI class is imported from the fastapi module to create the app instance.
Complete the code to import the Body function for request body parameters.
from fastapi import FastAPI, [1] app = FastAPI()
The Body function is used to declare request body parameters in FastAPI.
Fix the error in the function parameter to correctly use Body for multiple parameters.
from fastapi import FastAPI, Body app = FastAPI() @app.post("/items") async def create_item(name: str = [1], description: str = Body(...)): return {"name": name, "description": description}
To declare a body parameter with a default required value, use Body(...).
Fill both blanks to declare two required body parameters with descriptions.
from fastapi import FastAPI, Body app = FastAPI() @app.post("/users") async def create_user(username: str = [1], email: str = [2]): return {"username": username, "email": email}
Use Body(...) with description to declare required body parameters with helpful info.
Fill all three blanks to declare optional body parameters with default values and descriptions.
from fastapi import FastAPI, Body app = FastAPI() @app.post("/products") async def create_product(name: str = [1], price: float = [2], description: str = [3]): return {"name": name, "price": price, "description": description}
Use Body with default None or 0.0 and description to declare optional body parameters.