<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rifushigi</title>
    <description>The latest articles on DEV Community by Rifushigi (@rifushigi).</description>
    <link>https://dev.to/rifushigi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1380783%2F88ae7e66-c29c-45fc-91a4-a56c8e5597f6.jpg</url>
      <title>DEV Community: Rifushigi</title>
      <link>https://dev.to/rifushigi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rifushigi"/>
    <language>en</language>
    <item>
      <title>Catme — Building a FastAPI App</title>
      <dc:creator>Rifushigi</dc:creator>
      <pubDate>Sat, 18 Oct 2025 14:57:49 +0000</pubDate>
      <link>https://dev.to/rifushigi/catme-building-a-fastapi-app-2p35</link>
      <guid>https://dev.to/rifushigi/catme-building-a-fastapi-app-2p35</guid>
      <description>

&lt;p&gt;As part of HNG 13, I built a small yet complete &lt;strong&gt;FastAPI microservice&lt;/strong&gt; called &lt;strong&gt;Catme&lt;/strong&gt; — an API that returns developer profile info along with a random cat fact fetched asynchronously from &lt;a href="https://catfact.ninja" rel="noopener noreferrer"&gt;catfact.ninja&lt;/a&gt;.&lt;/p&gt;

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




&lt;h3&gt;
  
  
  What I Worked On
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Async API Calls&lt;/strong&gt;&lt;br&gt;
Used &lt;code&gt;httpx.AsyncClient&lt;/code&gt; 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?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rate Limiting with SlowAPI&lt;/strong&gt;&lt;br&gt;
Integrated &lt;code&gt;slowapi&lt;/code&gt; to protect the endpoints from abuse. Not sure why any would want to abuse a cat but you never know.&lt;br&gt;
Each route has its own limit:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/me&lt;/code&gt; → &lt;code&gt;5 requests/min&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/health&lt;/code&gt; → &lt;code&gt;10 requests/min&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Timestamping with UTC Awareness&lt;/strong&gt;&lt;br&gt;
Learned that &lt;code&gt;datetime.utcnow()&lt;/code&gt; is deprecated and also found out the hard way that autocomplete does not include brackets for method... Long story short I switched to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timezone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;utc&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;isoformat&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This returns an ISO 8601 UTC timestamp like:&lt;br&gt;
&lt;code&gt;2025-10-18T14:52:23.123456+00:00&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structured Exception Handling&lt;/strong&gt;&lt;br&gt;
Used FastAPI’s &lt;code&gt;HTTPException&lt;/code&gt; 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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testing with pytest + httpx&lt;/strong&gt;&lt;br&gt;
(ChatGpt 👀) Wrote async tests using &lt;code&gt;pytest.mark.asyncio&lt;/code&gt; and mocked external calls with &lt;code&gt;AsyncMock&lt;/code&gt;.&lt;br&gt;
The tests covered core behavior:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/health&lt;/code&gt; endpoint&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/me&lt;/code&gt; endpoint (success + failure cases)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fetch_cat_fact()&lt;/code&gt; async behavior&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Key Dependencies
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;FastAPI&lt;/strong&gt; – Modern async web framework&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Uvicorn&lt;/strong&gt; – ASGI server for running FastAPI&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HTTPX&lt;/strong&gt; – Async HTTP client&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;python-dotenv&lt;/strong&gt; – Manage environment variables&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;slowapi&lt;/strong&gt; – Rate limiting&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;pytest&lt;/strong&gt; – Unit testing framework&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  What I Learned
&lt;/h3&gt;

&lt;p&gt;This project reminded me that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Async programming in Python is &lt;strong&gt;cleaner than expected&lt;/strong&gt; once you get the hang of &lt;code&gt;httpx.AsyncClient&lt;/code&gt;... If it doesn't hang you first, hehehe.&lt;/li&gt;
&lt;li&gt;Rate limiting and observability should be &lt;strong&gt;built-in early&lt;/strong&gt;, not after the first DDoS scare 😅.&lt;/li&gt;
&lt;li&gt;Writing &lt;strong&gt;tests that simulate network failures&lt;/strong&gt; is key to robust systems. Especially now that I don't have to write it all myself 😁.&lt;/li&gt;
&lt;li&gt;Not-So-Little tools (like &lt;code&gt;dotenv&lt;/code&gt;) make your dev life cleaner and safer.&lt;/li&gt;
&lt;li&gt;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...&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fey2ivwq1hvvv32fbc7qu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fey2ivwq1hvvv32fbc7qu.png" alt="open-api endpoint" width="748" height="343"&gt;&lt;/a&gt;---&lt;/p&gt;

&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;Small projects like &lt;strong&gt;Catme&lt;/strong&gt; teach &lt;strong&gt;big(maybe not so big) architectural lessons&lt;/strong&gt;.&lt;br&gt;
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.” 🐱&lt;/p&gt;




</description>
      <category>python</category>
      <category>backend</category>
      <category>hng</category>
    </item>
  </channel>
</rss>
