feat: add /ping public API endpoint (#71)

This PR adds a new public API endpoint `/ping` which is more of an endpoint for debugging. It returns all search parameters, JSON request body, and request headers.

Example response:
```json
{
  "ping": "pong",
  "GET": {
    "foo": "bar"
  },
  "POST": [],
  "HEADERS": {
    "Te": "trailers",
    "Priority": "u=0, i",
    "Sec-Fetch-User": "?1",
    "Sec-Fetch-Site": "none",
    "Sec-Fetch-Mode": "navigate",
    "Sec-Fetch-Dest": "document",
    "Upgrade-Insecure-Requests": "1",
    "Sec-Gpc": "1",
    "Accept-Encoding": "gzip, deflate, br, zstd",
    "Accept-Language": "en-US,en;q=0.5",
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:144.0) Gecko/20100101 Firefox/144.0",
    "Host": "local.vlw.se:44302",
    "Content-Length": "",
    "Content-Type": ""
  },
  "datetime": {
    "date": "2026-03-29 11:20:30.775397",
    "timezone_type": 3,
    "timezone": "UTC"
  }
}
```

Reviewed-on: https://codeberg.org/vlw/vlw.se/pulls/71
This commit is contained in:
Victor Westerlund 2026-04-05 12:18:37 +02:00
parent 55a8234800
commit fdce8405cd
2 changed files with 25 additions and 0 deletions

23
api/ping/GET.php Normal file
View file

@ -0,0 +1,23 @@
<?php
use Reflect\{Response, Path};
use VLW\API\API;
require_once Path::root("src/API/API.php");
final class GET_Ping extends API {
public function __construct() {
parent::__construct();
}
public function main(): Response {
return new Response([
"ping" => "pong",
"GET" => $_GET,
"POST" => $_POST,
"HEADERS" => getallheaders(),
"datetime" => new DateTimeImmutable(),
]);
}
}

View file

@ -10,6 +10,7 @@ SET time_zone = "+00:00";
TRUNCATE TABLE `acl`; TRUNCATE TABLE `acl`;
INSERT INTO `acl` (`ref_group`, `ref_endpoint`, `method`) VALUES INSERT INTO `acl` (`ref_group`, `ref_endpoint`, `method`) VALUES
(NULL, 'ping', 'GET'),
(NULL, 'coffee', 'GET'), (NULL, 'coffee', 'GET'),
(NULL, 'languages', 'GET'), (NULL, 'languages', 'GET'),
(NULL, 'update', 'GET'), (NULL, 'update', 'GET'),
@ -19,6 +20,7 @@ INSERT INTO `acl` (`ref_group`, `ref_endpoint`, `method`) VALUES
TRUNCATE TABLE `endpoints`; TRUNCATE TABLE `endpoints`;
INSERT INTO `endpoints` (`id`, `active`) VALUES INSERT INTO `endpoints` (`id`, `active`) VALUES
('ping', 1),
('coffee', 1), ('coffee', 1),
('languages', 1), ('languages', 1),
('update', 1), ('update', 1),