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.
More on Testing, services & metrics
Why should automation scripts have tests at all?BeginnerHow does pytest discover and run tests?BeginnerWhy does pytest use plain `assert` instead of `assertEqual`?BeginnerWhat are pytest fixtures, and what scopes exist?IntermediateWhat built-in fixtures do you use most?IntermediateHow does `@pytest.mark.parametrize` work?Beginner