Creating API

Building My First ever Dynamic Profile API

This week started with my participation in HNG internship; with me shuttling between the two stacks namely: frontend web development and backend web development. It has been a challenging week;i saw that t…


This content originally appeared on DEV Community and was authored by oseniadewale

Building My First ever Dynamic Profile API

 This week started with my participation in HNG internship; with me shuttling between the two stacks namely: frontend web development and backend web development. It has been a challenging week;i saw that the backend was more challenging for me than the frontend (though it has its own numerous challenges) hence, i had to submit the frontend task first as soon as possible in order to focus on the backend.

For this, I worked on an interesting backend challenge as part of the HNG Internship Stage 0; a pre-requisite to move to Stage 1.

The task was to build simple RESTful API that returns my profile information along with a random cat fact fetched dynamically from the Cat Facts API: https://catfact.ninja/fact. It also has a timestamp that dynamically reflect the current UTC time at the moment of the request and update with every new request(of ISO 8601)

With my background grounded in PHP, i used PHP (OOP style) to build this simple yet powerful API.
The endpoint is available at /me, and it returns a structured JSON response in this format:
{
"status": "success",
"user": {
"email": "oseni246femi@gmail.com",
"name": "Oseni Adewale Oluwafemi",
"stack": "PHP/Laravel"
},
"timestamp": "2025-10-16T12:34:56.789Z",
"fact": "Cats sleep for 70% of their lives."
}
I created a small class called ApiClient to handle external API calls using cURL.
This class fetches data from the Cat Facts API (https://catfact.ninja/fact) every time the endpoint is accessed.
If the external API fails, the code gracefully handles the error by returning a fallback message instead of breaking the response.

The API also dynamically generates the current UTC timestamp in ISO 8601 format to ensure consistency.

I integrated the Cat Facts API inside my project using PHP’s cURL functions.
Every time a user hits the '/me endpoint', the script makes a real-time HTTP request to 'https://catfact.ninja/fact' and retrieves a fresh random fact about cats.

This helped me understand how third-party API consumption works in real-world applications — handling network errors, setting timeouts, and ensuring data is returned in the correct JSON format.

It was a great experience building something small yet meaningful that demonstrates how backend logic, API integration, and deployment come together.

Demonstration of the API can be found in the Railway app here: https://apiforhngassignment-production.up.railway.app/me

My githubGitHub Repo:https://github.com/oseniadewale/api_for_hng_assignment

What amazes me is that i have never on my own build an API but this task actually pushed me to a greater height in software development and i cant but agree with my motto philosophy that:
'if you can dream it; you can build it'


This content originally appeared on DEV Community and was authored by oseniadewale


Print Share Comment Cite Upload Translate Updates
APA

oseniadewale | Sciencx (2025-10-17T14:57:09+00:00) Creating API. Retrieved from https://www.scien.cx/2025/10/17/creating-api/

MLA
" » Creating API." oseniadewale | Sciencx - Friday October 17, 2025, https://www.scien.cx/2025/10/17/creating-api/
HARVARD
oseniadewale | Sciencx Friday October 17, 2025 » Creating API., viewed ,<https://www.scien.cx/2025/10/17/creating-api/>
VANCOUVER
oseniadewale | Sciencx - » Creating API. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/10/17/creating-api/
CHICAGO
" » Creating API." oseniadewale | Sciencx - Accessed . https://www.scien.cx/2025/10/17/creating-api/
IEEE
" » Creating API." oseniadewale | Sciencx [Online]. Available: https://www.scien.cx/2025/10/17/creating-api/. [Accessed: ]
rf:citation
» Creating API | oseniadewale | Sciencx | https://www.scien.cx/2025/10/17/creating-api/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.