DEV Community

Rifushigi
Rifushigi

Posted on

Catme — Building a FastAPI App


As part of HNG 13, I built a small yet complete FastAPI microservice called Catme — an API that returns developer profile info along with a random cat fact fetched asynchronously from catfact.ninja.

This is my first time using FastAPI and it was quite interesting that it repped its name pretty well... I had some hands-on exercise in async programming, structured error handling, and rate-limiting — .


What I Worked On

Async API Calls
Used httpx.AsyncClient to make non-blocking requests to the Cat Facts API — it wasn't necessary given the small scale of the app but it doesn't hurt to use it, so why not?

Rate Limiting with SlowAPI
Integrated slowapi to protect the endpoints from abuse. Not sure why any would want to abuse a cat but you never know.
Each route has its own limit:

  • /me5 requests/min
  • /health10 requests/min

Timestamping with UTC Awareness
Learned that datetime.utcnow() is deprecated and also found out the hard way that autocomplete does not include brackets for method... Long story short I switched to:

datetime.now(timezone.utc).isoformat()
Enter fullscreen mode Exit fullscreen mode

This returns an ISO 8601 UTC timestamp like:
2025-10-18T14:52:23.123456+00:00

Structured Exception Handling
Used FastAPI’s HTTPException to wrap timeout errors, external API issues, and unexpected runtime problems cleanly. Though I felt it was a bit repetitive but a first timer can't complain.

Testing with pytest + httpx
(ChatGpt 👀) Wrote async tests using pytest.mark.asyncio and mocked external calls with AsyncMock.
The tests covered core behavior:

  • /health endpoint
  • /me endpoint (success + failure cases)
  • fetch_cat_fact() async behavior

Key Dependencies

  • FastAPI – Modern async web framework
  • Uvicorn – ASGI server for running FastAPI
  • HTTPX – Async HTTP client
  • python-dotenv – Manage environment variables
  • slowapi – Rate limiting
  • pytest – Unit testing framework

What I Learned

This project reminded me that:

  • Async programming in Python is cleaner than expected once you get the hang of httpx.AsyncClient... If it doesn't hang you first, hehehe.
  • Rate limiting and observability should be built-in early, not after the first DDoS scare 😅.
  • Writing tests that simulate network failures is key to robust systems. Especially now that I don't have to write it all myself 😁.
  • Not-So-Little tools (like dotenv) make your dev life cleaner and safer.
  • And apparently, it has OOTB support for swagger!!! That's a favourite for me. Look out for the endpoint below if you can find it...

open-api endpoint---

Final Thoughts

Small projects like Catme teach big(maybe not so big) architectural lessons.
Next step? Containerize with Docker, set up CI/CD using GitHub Actions, and maybe add a frontend that displays “your cat fact of the day.” 🐱


Top comments (0)