id/api.php

41 lines
884 B
PHP
Raw Normal View History

<?php
header('Content-Type: application/json');
2024-07-03 14:20:39 +01:00
$routes = [
'' => function () {
header('Location: /api/status');
exit();
},
'status' => function () {
http_response_code(200);
return [
'response' => [
'success' => true,
'status_code' => 200
],
'body' => [
'message' => 'Science compels us to explode the sun!',
'time' => time()
]
];
}
];
2024-07-03 14:20:39 +01:00
if (array_key_exists($path[1], $routes)) {
$res = $routes[$path[1]]();
echo json_encode($res, JSON_PRETTY_PRINT);
} else {
echo json_encode([
"response" => [
"success" => false,
"status_code" => 404
],
'body' => [
'message' => 'That endpoint could not be found.'
]
], JSON_PRETTY_PRINT);
}