<?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>Forem: oseniadewale</title>
    <description>The latest articles on Forem by oseniadewale (@oseniadewale).</description>
    <link>https://forem.com/oseniadewale</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%2F3571195%2F50340dd4-30e1-4d67-aafe-2cf22f529cbb.jpg</url>
      <title>Forem: oseniadewale</title>
      <link>https://forem.com/oseniadewale</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/oseniadewale"/>
    <language>en</language>
    <item>
      <title>Creating API</title>
      <dc:creator>oseniadewale</dc:creator>
      <pubDate>Fri, 17 Oct 2025 14:57:09 +0000</pubDate>
      <link>https://forem.com/oseniadewale/creating-api-1c91</link>
      <guid>https://forem.com/oseniadewale/creating-api-1c91</guid>
      <description>&lt;p&gt;Building My First ever Dynamic Profile API &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; 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.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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: &lt;a href="https://catfact.ninja/fact" rel="noopener noreferrer"&gt;https://catfact.ninja/fact&lt;/a&gt;. 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) &lt;/p&gt;

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

&lt;p&gt;The API also dynamically generates the current UTC timestamp in ISO 8601 format to ensure consistency.&lt;/p&gt;

&lt;p&gt;I integrated the Cat Facts API inside my project using PHP’s cURL functions.&lt;br&gt;
Every time a user hits the '/me endpoint', the script makes a real-time HTTP request to '&lt;a href="https://catfact.ninja/fact" rel="noopener noreferrer"&gt;https://catfact.ninja/fact&lt;/a&gt;' and retrieves a fresh random fact about cats.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;It was a great experience building something small yet meaningful that demonstrates how backend logic, API integration, and deployment come together.&lt;/p&gt;

&lt;p&gt;Demonstration of the API can be found in the Railway app here: &lt;a href="https://apiforhngassignment-production.up.railway.app/me" rel="noopener noreferrer"&gt;https://apiforhngassignment-production.up.railway.app/me&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My githubGitHub Repo:&lt;a href="https://github.com/oseniadewale/api_for_hng_assignment" rel="noopener noreferrer"&gt;https://github.com/oseniadewale/api_for_hng_assignment&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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: &lt;br&gt;
&lt;strong&gt;'if you can dream it; you can build it'&lt;/strong&gt;&lt;/p&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%2Ff6zf6kbz9kjkr1he26d6.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%2Ff6zf6kbz9kjkr1he26d6.PNG" alt=" " width="800" height="397"&gt;&lt;/a&gt;&lt;br&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%2F8ygv57zrjaqwmdor8lz2.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%2F8ygv57zrjaqwmdor8lz2.PNG" alt=" " width="800" height="429"&gt;&lt;/a&gt;&lt;br&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%2Fi0vpm6rr26228s2q01ix.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%2Fi0vpm6rr26228s2q01ix.PNG" alt=" " width="800" height="454"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>api</category>
      <category>learning</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
