A fictional currency exchange platform with real-time rates, historical charts, and a currency calculator. Includes both a frontend website and a standalone REST API.
forex/
├── api/ # REST API (standalone)
│ ├── config/
│ ├── public/
│ └── src/
├── website/ # Frontend application
│ ├── config/
│ ├── public/
│ └── src/
├── LICENSE
└── README.md
A PHP REST API for converting between virtual and real-world currencies. Uses the Frankfurter API for real-time forex rates.
- Convert between virtual and real currencies
- Get current exchange rates for all currencies
- Retrieve historical exchange rates
- Built-in CORS support
- File-based rate limiting (no Redis required)
- PSR-4 autoloading
- PHP 8.0+
- MySQL/MariaDB
- Composer
- cURL extension
-
Install dependencies
cd api composer install -
Configure the application
cp config/app.php.example config/app.php
Edit
config/app.phpwith your database credentials. -
Set up the database
Create a
currenciestable:CREATE TABLE currencies ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100) NOT NULL, code VARCHAR(10) NOT NULL UNIQUE, symbol VARCHAR(10), country VARCHAR(100), subdivision VARCHAR(100), exchange_rate DECIMAL(20, 10) NOT NULL, real_currency VARCHAR(10) NOT NULL );
-
Configure your web server
Point your document root to the
api/public/directory.
GET ?action=list
Response:
{
"success": true,
"action": "list",
"data": [
{
"name": "Vyrth",
"short": "VYR",
"symbol": "$",
"country": "Gurkistan",
"breakdown": "100 cents",
"exchange_rate": "1.0000000000",
"forex": "EUR"
}
]
}GET ?action=convert&amount={amount}&from={from_code}&to={to_code}
Example:
GET ?action=convert&amount=100&from=VYR&to=EUR
Response:
{
"success": true,
"action": "convert",
"data": {
"from": "VYR",
"to": "EUR",
"amount": 100,
"result": 92.45
}
}GET ?action=rates&base={base_code}
Response:
{
"success": true,
"action": "rates",
"data": {
"base": "VYR",
"rates": {
"EUR": {
"value": 0.9245,
"change": 0.0,
"timestamp": "2024-01-15T12:00:00+00:00"
}
}
}
}GET ?action=historical&from={from}&to={to}&start={YYYY-MM-DD}&end={YYYY-MM-DD}
Response:
{
"success": true,
"action": "historical",
"data": {
"from": "VYR",
"to": "EUR",
"start_date": "2024-01-01",
"end_date": "2024-01-07",
"rates": [
{"date": "2024-01-01", "rate": 0.9245},
{"date": "2024-01-02", "rate": 0.9250}
]
}
}{
"success": false,
"error": {
"code": 400,
"message": "Missing required parameter: 'amount' for action 'convert'."
}
}| Code | Description |
|---|---|
| 200 | Success |
| 400 | Bad Request (missing/invalid params) |
| 404 | Not Found (currency/action not found) |
| 405 | Method Not Allowed |
| 429 | Rate Limit Exceeded |
| 502 | Bad Gateway (external API error) |
| 503 | Service Unavailable (database error) |
- Default: 60 requests per minute per IP
- Headers:
X-RateLimit-Limit,X-RateLimit-Remaining,X-RateLimit-Reset
Edit api/config/app.php:
return [
'database' => [
'host' => 'localhost',
'name' => 'your_db',
'user' => 'your_user',
'pass' => 'your_password',
],
'cors' => [
'allowed_origins' => ['https://your-frontend.com'],
],
'rate_limit' => [
'enabled' => true,
'requests_per_minute' => 60,
],
'api' => [
'debug' => false,
],
];- PHP 7.4 or higher
- cURL extension enabled
- Web server (Apache, nginx, or PHP built-in server)
- Upload the contents of this repository to your web server
- Ensure
website/public/is your document root - Edit
website/config/app.phpto adjust settings
Edit website/config/app.php:
return [
'api' => [
'base_url' => 'https://your-api-endpoint.com/api',
'timeout' => 15,
],
'defaults' => [
'base_currency' => 'EUR',
'target_currency' => 'USD',
],
'ui' => [
'site_name' => 'Your Site Name',
],
];Override the API URL using an environment variable:
export API_BASE="https://your-api.com/api"MIT License - See LICENSE file for details.
- Exchange rates by Frankfurter API
- Charts powered by LightweightCharts
- Styling with Tailwind CSS
- Fonts: DM Serif Display, Source Sans 3