Part 1 — Consume 3rd-Party API & Validate Data
API chosen: Cat Facts (from the free-APIs catalog). Endpoint: https://catfact.ninja/facts?limit=25.
Tech: Python, requests (HTTP), pydantic (validation), SQLAlchemy + SQLite (DB).
Process: -Fetch JSON facts. -Validate structure with Pydantic models -Save valid rows to catfacts.db table cat_facts(id, fact, length).
Why this meets Part 1: Public JSON API → validated → persisted.
Part 2 — RESTful API with CRUD + Persistence + Docs
Framework: FastAPI
Models: Request: CatFactCreate { fact, length } (Pydantic).
Response: CatFactRead { id, fact, length }.
Endpoints:
POST /facts → create a fact
GET /facts → list facts
GET /facts/{id} → read one
PUT /facts/{id} → update
DELETE /facts/{id} → delete
Storage: Uses the same SQLite DB via SQLAlchemy ORM.
Why this meets Part 2: Full CRUD, durable DB writes, and Swagger UI for API documentation
Part 3 — Error Handling, Security, and Testing
-Error Handling:
Middleware logs request time and returns JSON on unexpected 500.
Uniform handlers for HTTPException (e.g., 404/400) and validation errors (422).
-Security:
HTTPS for secure transport (start Uvicorn with --ssl-keyfile + --ssl-certfile using a self-signed cert).
Optional hardening: HTTPS redirect, Trusted Hosts, and CORS allow-list.
Secrets hygiene via .env
Testing (Postman):
Happy path: POST → GET(all) → GET(id) → PUT → DELETE (collection provided).
Negative tests:
-GET /facts/9999999 → 404
-POST bad body { "fact": "" } → 422
-POST mismatch { "fact": "ABC", "length": 99 } → 400