Project import generated by Copybara.
GitOrigin-RevId: 63746295f1a5ab5a619056791995793d65529e62
diff --git a/src/inc/api.php b/src/inc/api.php
new file mode 100644
index 0000000..9b606be
--- /dev/null
+++ b/src/inc/api.php
@@ -0,0 +1,28 @@
+<?php
+class api {
+ public static function inputJson() {
+ $string = trim(file_get_contents("php://input"));
+
+ if (empty($string)) return false;
+
+ $json = json_decode($string, true);
+
+ if (json_last_error() !== JSON_ERROR_NONE) return false;
+
+ return $json;
+ }
+
+ public static function error($message = null) {
+ if ($message !== null) self::write([
+ 'error' => true,
+ 'message' => $message,
+ ]);
+ http_response_code(400);
+ exit();
+ }
+
+ public static function write($array) {
+ header('Content-Type: application/json');
+ echo json_encode($array);
+ }
+}