Using Inspectr with FastAPI
FastAPI is a high-performance Python web framework, ideal for building modern APIs. Inspectr lets you debug traffic, inspect payloads, and securely expose your FastAPI endpoints with minimal configuration.
This guide walks you through using Inspectr with a FastAPI project.
Prerequisites
Section titled “Prerequisites”- Python 3.8+
- FastAPI and Uvicorn installed:
pip install fastapi uvicorn
- Inspectr installed (Install guide →)
Step 1: Create or Run a FastAPI App
Section titled “Step 1: Create or Run a FastAPI App”Here’s a simple FastAPI app (main.py
):
from fastapi import FastAPI
app = FastAPI()
@app.get("/hello")def read_root(): return {"message": "Hello from FastAPI!"}
Start the server:
uvicorn main:app --port 5001
Step 2: Start Inspectr to Forward Traffic
Section titled “Step 2: Start Inspectr to Forward Traffic”inspectr --listen=:8080 --backend=http://localhost:5001
Make a request via Inspectr:
curl http://localhost:8080/hello
- The request is forwarded to FastAPI
- The response is captured in Inspectr
- You can view it in the App UI: http://localhost:4004
Optional: Expose FastAPI Publicly
Section titled “Optional: Expose FastAPI Publicly”inspectr \ --listen=:8080 \ --backend=http://localhost:5001 \ --expose \ --channel=fastapi-demo \ --channel-code=fastapi123
Your public endpoint:
https://fastapi-demo.in-spectr.dev
Summary
Section titled “Summary”Inspectr + FastAPI gives you:
- Simple request logging and inspection
- Public webhook endpoint for testing
- Real-time debugging and replay