Initial setup, not working yet
This commit is contained in:
35
frontend/api/client.php
Normal file
35
frontend/api/client.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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);
|
||||
}
|
||||
Reference in New Issue
Block a user