blob: c13b15c32c47b9ae5fcf5834862ee82aa4a59758 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<?php
/**
* Functions for intercting with the remote API.
*
* @package volse.faktura.web
*/
namespace Faktura\API;
define('API_URL', 'http://postgrest:3000');
function call(string $method, string $resource, mixed $data = null): string {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, API_URL . '/' . $resource);
curl_setopt($ch, CURLOPT_HEADER, 'Accept: application/json');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
if ($result === false) {
echo curl_error($ch);
die();
}
curl_close($ch);
return $result;
}
|