Interview Prep/Python for DevOps/Testing, services & metrics

How do you build the same service in FastAPI, and why do teams choose it?

IntermediateConceptTesting, services & metrics
Answer
from fastapi import FastAPI, Response
from pydantic import BaseModel
app = FastAPI()

class Deploy(BaseModel):
    service: str
    version: str

@app.get("/healthz")
async def healthz():
    return {"status": "ok"}

@app.post("/deploy", status_code=202)
async def deploy(req: Deploy):
    enqueue(req)
    return {"accepted": req.service}

Run with uvicorn app:app --host 0.0.0.0 --port 8000 (or fastapi run). FastAPI validates bodies from type hints via pydantic, returns 422 with field errors automatically, generates OpenAPI docs at /docs, and supports async handlers.

All Python for DevOps questions Roadmap: Python for automation

More on Testing, services & metrics