from fastapi import FastAPI
from fastapi.responses import HTMLResponse
app = FastAPI(
title="Vercel + FastAPI",
description="Vercel + FastAPI",
version="1.0.0",
)
@app.post("/api/echo")
async def foo(payload: dict):
return {"received_payload": payload}
@app.get("/api/data")
def get_sample_data():
return {
"data": [
{"id": 1, "name": "Sample Item 1", "value": 100},
{"id": 2, "name": "Sample Item 2", "value": 200},
{"id": 3, "name": "Sample Item 3", "value": 300}
],
"total": 3,
"timestamp": "2024-01-01T00:00:00Z"
}
@app.get("/api/items/{item_id}")
def get_item(item_id: int):
return {
"item": {
"id": item_id,
"name": "Sample Item " + str(item_id),
"value": item_id * 100
},
"timestamp": "2024-01-01T00:00:00Z"
}
@app.get("/", response_class=HTMLResponse)
def read_root():
return """
Vercel + FastAPI
Vercel + FastAPI
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Python": "on Vercel"}
Interactive API Docs
Explore this API's endpoints with the interactive Swagger UI. Test requests and view response schemas in real-time.
Open Swagger UI →
Sample Data
Access sample JSON data through our REST API. Perfect for testing and development purposes.
Get Data →
"""
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=5001, reload=True)