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
Method | Endpoint | Description |
---|---|---|
GET |
/api/me |
Returns your profile info and a dynamic cat fact |
- Framework: Laravel 12+
- Language: PHP 8.1+
- HTTP Client: Laravel HTTP (based on Guzzle)
- Logging: Laravel Log Channel (default)
- Rate limiting: Laravel Throttle Middleware
Before running locally, ensure you have:
- PHP 8.1 or later
- Composer
- WAMP / XAMPP / LARAGON
- Git
- Internet connection (for fetching cat facts)
git clone https://github.com/integral-hub/backend-api.git
cd backend-api
composer install
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
php artisan serve
The API will be available at:
http://127.0.0.1:8000/api/me
GET /api/me
{
"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."
}
{
"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."
}
✅ 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
app/
├── Http/
│ └── Controllers/
│ └── UserController.php
├── Interfaces/
│ └── UserInterface.php
├── Services/
│ └── UserService.php
└── Responses/
├── ApiResponse.php
├── SuccessResponse.php
└── ErrorResponse.php
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 |
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
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
.
Name: Abiodun ADEOSUN Stack: Laravel / PHP LinkedIn: linkedinprofile