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 accept connections.
Complete the code to define a GET route at the root path that returns a welcome message.
@app.[1]("/") async def read_root(): return {"message": "Welcome!"}
The @app.get decorator defines a GET route to accept connections at the root path.
Fix the error in the code to run the FastAPI app with uvicorn on port 8000.
import uvicorn if __name__ == "__main__": uvicorn.run("main:[1]", host="127.0.0.1", port=8000, reload=True)
The string "main:app" tells uvicorn to find the app instance in the main module.
Fill both blanks to create a POST route at '/submit' that accepts JSON data and returns it.
@app.[1]("/submit") async def submit_data(data: [2]): return data
Use @app.post to define a POST route and dict to accept JSON data as a Python dictionary.
Fill all three blanks to create a FastAPI app that accepts connections on all interfaces at port 8080 with reload enabled.
import uvicorn if __name__ == "__main__": uvicorn.run("main:[1]", host="[2]", port=[3], reload=True)
Use app as the FastAPI instance name, 0.0.0.0 to accept connections from all interfaces, and port 8080 as specified.