Day 1 of my internship. The task seemed simple: "Build an API endpoint that returns your profile and a cat fact."
How hard could it be? Spoiler: I learned more from this "simple" task than from watching 10 hours of tutorials.
The Challenge
Build a /me endpoint that:
Returns my profile info
Fetches random cat facts from an external API
Updates timestamp on every request
Doesn't crash when things go wrong
My Stack: Python + FastAPI
The "Aha!" Moments
- External APIs Are Unreliable (And That's Normal)
My first version looked like this:
python@app.get("/me") async def get_profile(): response = await client.get("https://catfact.ninja/fact") cat_fact = response.json()["fact"] return {"fact": cat_fact, ...}
What could go wrong?
API is down → My app crashes
API is slow → User waits forever
API returns weird data → App explodes
The fix: Timeouts + error handling + fallbacks
pythonasync def fetch_cat_fact():
try:
async with httpx.AsyncClient(timeout=5.0) as client:
response = await client.get(CAT_FACT_API_URL)
return response.json()["fact"]
except:
return "Cat facts temporarily unavailable"
Lesson learned: Always plan for failure. Production apps need to be resilient, not just functional.
- Environment Variables Aren't Just for Secrets I hardcoded my email in the code at first. Then I realized:
What if I want to change it?
What if someone else uses my code?
What about deployment?
Created .env for my actual data:
bashUSER_EMAIL=john@example.com
USER_NAME=John Doe
Created .env.example for the template:
bashUSER_EMAIL=your.email@example.com
USER_NAME=Your Name
Lesson learned: Separate configuration from code. Future you will thank present you.
- FastAPI's Auto-Docs Saved Me Hours
Hit localhost:8000/docs and boom.....interactive API documentation, automatically generated. I could test everything right in the browser without writing a single line of test code.
Lesson learned: Choose tools that give you superpowers for free.
The Final Result
Live API: [https://profile-api-production-f700.up.railway.app/me]
json{
"status": "success",
"user": {
"email": "john@example.com",
"name": "John Doe",
"stack": "Python/FastAPI"
},
"timestamp": "2025-10-17T14:30:45.123456+00:00",
"fact": "Cats sleep 70% of their lives."
}
Every request fetches a new cat fact. Every timestamp is fresh. And when the cat API goes down? My API keeps working.
What This Task Actually Taught Me
Beyond the code:
Error handling > happy path — Production is messy
Async is powerful — Don't block your API
Never commit secrets — .gitignore is your friend
Documentation matters — README = first impression
Deploy early, deploy often — See your code in production
The unexpected lesson: A "simple" task reveals how much you don't know. And that's exactly the point of learning.
The Stack
Framework: FastAPI (because async + auto-docs = ❤️)
HTTP Client: httpx (for async requests)
Deployment: Railway (GitHub integration made it painless)
External API: Cat Facts API
Try It Yourself
GitHub: [https://github.com/Titilola-py/profile-api]
Live Demo: [https://profile-api-production-f700.up.railway.app/me]
Clone it. Break it. Fix it. Learn.
Questions? Built something similar? Drop a comment! I'd love to see what you created or hear about your first API experience.
Connect with me here:
GitHub: [https://github.com/Titilola-py] | LinkedIn: [https://www.linkedin.com/in/fatimah-olaitan-4bb6602a4/] | Twitter: [https://x.com/thetitilola]
Top comments (0)