Complete the code to import the FastAPI class needed to create an app.
from fastapi import [1] app = [1]()
The FastAPI class is imported to create the app instance. This is the main entry point for your API.
Complete the code to define a GET endpoint that returns a welcome message.
@app.[1]("/") async def root(): return {"message": "Welcome to FastAPI!"}
The @app.get decorator defines a GET HTTP method endpoint. This is used to retrieve data.
Fix the error in the code to enable automatic API docs with Swagger UI.
from fastapi import FastAPI app = FastAPI(docs_url=[1]) @app.get("/items/{item_id}") async def read_item(item_id: int): return {"item_id": item_id}
The default Swagger UI docs URL is '/docs'. Setting docs_url to '/docs' enables the automatic API documentation.
Fill both blanks to customize the OpenAPI title and version in the FastAPI app.
app = FastAPI(title=[1], version=[2])
You can customize the API documentation by setting the title and version parameters when creating the FastAPI app.
Fill all three blanks to add a description, contact email, and license info to the OpenAPI docs.
app = FastAPI(
description=[1],
contact=[2],
license_info=[3]
)FastAPI allows adding extra metadata like description, contact, and license_info to the OpenAPI docs by passing these parameters as strings or dictionaries.