36 lines
735 B
PHP
36 lines
735 B
PHP
<?php
|
|
|
|
require_once __DIR__ . "/config.php";
|
|
|
|
function api_request($method, $endpoint, $data = null, $token = null) {
|
|
|
|
$ch = curl_init(API_BASE . $endpoint);
|
|
|
|
$headers = [
|
|
"Content-Type: application/json"
|
|
];
|
|
|
|
if ($token) {
|
|
$headers[] = "Authorization: Bearer " . $token;
|
|
}
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
|
|
|
if ($data !== null) {
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
|
}
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
|
$response = curl_exec($ch);
|
|
|
|
if ($response === false) {
|
|
die(curl_error($ch));
|
|
}
|
|
|
|
curl_close($ch);
|
|
|
|
return json_decode($response, true);
|
|
}
|