Q&A 5 How do you run and test your FastAPI app using Uvicorn and Swagger UI?
5.1 Explanation
After creating your FastAPI app, you need to run it locally to test prediction endpoints. The standard way to run FastAPI is through Uvicorn, an ASGI server that supports fast, async APIs.
When you run your app, FastAPI automatically provides an interactive, browser-based Swagger UI at /docs, where you can test endpoints and submit real input.
5.2 Run Command (Terminal)
Assuming your FastAPI file is located at scripts/model_api.py and your app instance is named app, run:
- script.model_api is the Python path: folder + filename (without .py)
- :app refers to the FastAPI() instance inside the file
- –reload enables live reloading during development
5.3 Output (Sample)
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) INFO: Started reloader process…
5.4 Test in Your Browser
You’ll see:
- /models → GET endpoint to list all available models
- /predict/{model_name} → POST endpoint with a form to test predictions
Click “Try it out” on any route, fill in the form, and hit Execute to see the response.