24 lines
563 B
PHP
24 lines
563 B
PHP
<?php
|
|
|
|
class RestApi {
|
|
|
|
// Получить данные из JSON запроса
|
|
public static function getInput(): array {
|
|
$json = file_get_contents('php://input');
|
|
$data = json_decode($json, true);
|
|
|
|
return $data ?? [];
|
|
}
|
|
|
|
// Отправить JSON ответ
|
|
public static function response($data, int $code = 200): void {
|
|
http_response_code($code);
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
|
|
}
|
|
|
|
?>
|