diff options
Diffstat (limited to 'web/include/api.php')
-rw-r--r-- | web/include/api.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/web/include/api.php b/web/include/api.php new file mode 100644 index 0000000..c13b15c --- /dev/null +++ b/web/include/api.php @@ -0,0 +1,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; +} + |