Skip to content

integral-hub/backend-api

Repository files navigation

Backend Wizards — Stage 0: Dynamic Profile Endpoint

📋 Project Overview

building a dynamic RESTful API endpoint /api/me that returns your profile information along with a random cat fact fetched from an external API.

It demonstrates key backend concepts including:

  • API design & structure (Laravel)
  • Service abstraction and interface-driven architecture
  • Integration with a third-party API
  • Dynamic timestamp formatting (ISO 8601)
  • Error handling, logging, and rate limiting

🚀 Endpoint Summary

Method Endpoint Description
GET /api/me Returns your profile info and a dynamic cat fact

📦 Tech Stack

  • Framework: Laravel 12+
  • Language: PHP 8.1+
  • HTTP Client: Laravel HTTP (based on Guzzle)
  • Logging: Laravel Log Channel (default)
  • Rate limiting: Laravel Throttle Middleware

🧰 Requirements

Before running locally, ensure you have:

  • PHP 8.1 or later
  • Composer
  • WAMP / XAMPP / LARAGON
  • Git
  • Internet connection (for fetching cat facts)

⚙️ Installation & Setup

1️⃣ Clone the repository

git clone https://github.com/integral-hub/backend-api.git
cd backend-api

2️⃣ Install dependencies

composer install

3️⃣ Configure environment

Copy the .env.example file and update variables:

cp .env.example .env
php artisan key:generate

Then open .env and ensure you have:

APP_NAME="Backend API"
APP_ENV=local
APP_DEBUG=true
APP_URL=http://localhost:8000

# External API Configurations
CAT_FACTS_URL=https://catfact.ninja/fact
CAT_FACTS_TIMEOUT=10

4️⃣ Run the application

php artisan serve

The API will be available at:

http://127.0.0.1:8000/api/me

🧪 Testing the Endpoint

Request

GET /api/me

Example Successful Response

{
  "status": "success",
  "user": {
    "email": "you@example.com",
    "name": "Full Name",
    "stack": "Laravel/PHP"
  },
  "timestamp": "2025-10-16T13:00:00.123Z",
  "fact": "Cats have five toes on their front paws but only four toes on their back paws."
}

Example Fallback Response (if Cat Facts API fails)

{
  "status": "success",
  "user": {
    "email": "you@example.com",
    "name": "Full Name",
    "stack": "Laravel/PHP"
  },
  "timestamp": "2025-10-16T13:00:00.123Z",
  "fact": "Could not fetch a cat fact at this time."
}

🛡️ Features & Best Practices

✅ Dynamic UTC timestamp in ISO 8601 format ✅ Random cat fact fetched on every request ✅ Fallback on API failure ✅ Basic logging for debugging ✅ Rate limiting to prevent abuse (5 requests per minute) ✅ Interface + Service pattern for clean separation of concerns ✅ Follows PSR-4 and SOLID principles


🧩 Project Structure

app/
 ├── Http/
 │   └── Controllers/
 │        └── UserController.php
 ├── Interfaces/
 │   └── UserInterface.php
 ├── Services/
 │   └── UserService.php
 └── Responses/
      ├── ApiResponse.php
      ├── SuccessResponse.php
      └── ErrorResponse.php

🔧 Environment Variables

Variable Description Default
CAT_FACTS_URL External API endpoint for cat facts https://catfact.ninja/fact
CAT_FACTS_TIMEOUT Timeout (seconds) for external request 10

📜 Logging

All API request logs and error messages are stored under:

storage/logs/laravel.log

Example log entries include:

  • API success/failure events
  • Timeout or connection errors

🚦 Rate Limiting

The /me endpoint is protected by Laravel’s default throttle middleware:

Route::middleware('throttle:5,1')->get('/me', [UserController::class, 'show']);

→ allows 5 requests per minute per IP before returning HTTP 429.



🧑‍💻 Author

Name: Abiodun ADEOSUN Stack: Laravel / PHP LinkedIn: linkedinprofile


About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages