Serve a fake customer API as /api/customer/:id
with Apache and some PHP.
/srv/http/api/customer/index.php
:
<?php
// Simple customer array (simulate a database)
$customers = [
1 => [
'first_name' => 'Alice',
'last_name' => 'Smith',
'status' => 'active'
],
2 => [
'first_name' => 'Bob',
'last_name' => 'Johnson',
'status' => 'inactive'
]
];
// Get the request URI and method
$requestUri = $_SERVER['REQUEST_URI'];
$requestMethod = $_SERVER['REQUEST_METHOD'];
// Basic routing logic
if ($requestMethod === 'GET' && preg_match('#^/api/customer/(\d+)$#', $requestUri, $matches)) {
$customerId = (int)$matches[1];
if (isset($customers[$customerId])) {
header('Content-Type: application/json');
echo json_encode($customers[$customerId]);
} else {
http_response_code(404);
echo json_encode(['error' => 'Customer not found']);
}
} else {
http_response_code(400);
echo json_encode(['error' => 'Invalid request']);
}
Redirect all requests in the same folder:
/srv/http/api/customer/.htaccess
:
RewriteEngine On
RewriteRule ^ index.php [L]