A simple RESTful API endpoint that returns your profile information along with a dynamic cat fact fetched from an external API.
- Profile Information: Returns your personal details including name, email, and tech stack
- Dynamic Cat Facts: Fetches random cat facts from the Cat Facts API
- RESTful Design: Clean API endpoint following REST principles
- Error Handling: Comprehensive error handling with custom middleware
- CORS Support: Cross-origin resource sharing enabled
- Timeout Protection: Built-in request timeout to prevent hanging requests
- Node.js (version 14 or higher)
- npm (Node Package Manager)
-
Clone the repository
git clone https://github.com/yourusername/Dynamic-Profile-Endpoint.git cd Dynamic-Profile-Endpoint -
Navigate to the app directory
cd app -
Install dependencies
npm install
npm run devThis will start the server with nodemon for automatic restarts on file changes.
npm startThis will start the server in production mode.
The server will start on http://localhost:3000 by default.
- express (^5.1.0) - Web framework for Node.js
- cors (^2.8.5) - Cross-Origin Resource Sharing middleware
- dotenv (^17.2.3) - Environment variable loader
- node-fetch (^3.3.2) - HTTP request library for Node.js
- nodemon (^3.1.10) - Development tool that automatically restarts the server
Create a .env file in the app directory with the following variables:
PORT=3000Note: The PORT variable is optional. If not provided, the server will default to port 3000.
Returns your profile information along with a random cat fact.
Response Example:
{
"status": "success",
"user": {
"email": "humpheryufuoma@gmail.com",
"name": "Otuoniyo Ufuoma-Oghene Humphery",
"stack": "Backend-0"
},
"timestamp": "2024-01-15T10:30:00.000Z",
"fact": "Cats have over 30 muscles controlling their ears."
}app/
├── controllers/
│ └── controller.js # API route handlers
├── middleware/
│ ├── errorHandler.js # Error handling middleware
│ └── notFound.js # 404 handler middleware
├── route/
│ └── route.js # Route definitions
├── utils/
│ └── fetchWithTimeout.js # HTTP client with timeout
├── app.js # Express app configuration
├── server.js # Server entry point
└── package.json # Dependencies and scripts
The API includes comprehensive error handling:
- Timeout Errors: Requests that exceed 30 seconds will be aborted
- HTTP Errors: Non-2xx responses are properly handled
- 404 Errors: Custom middleware for undefined routes
- Server Errors: Centralized error handling middleware
- Cat Facts API:
https://catfact.ninja/fact- Provides random cat facts
This project is licensed under the ISC License.
Otuoniyo Ufuoma-Oghene Humphery
- Email: humpheryufuoma@gmail.com
- Stack: Backend-0