polish the api route, response, health, cache, and metrics
This commit is contained in:
34
app/helpers/http.php
Normal file
34
app/helpers/http.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
// app/helpers/http.php
|
||||
function http_post_form($url, array $fields, array $headers = [], $timeout = 10) {
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => http_build_query($fields),
|
||||
CURLOPT_HTTPHEADER => $headers,
|
||||
CURLOPT_TIMEOUT => $timeout,
|
||||
]);
|
||||
$body = curl_exec($ch);
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$err = curl_error($ch);
|
||||
curl_close($ch);
|
||||
return [$code, $body, $err];
|
||||
}
|
||||
|
||||
function http_post_json($url, array $json, array $headers = [], $timeout = 10) {
|
||||
$hdrs = array_merge(['Content-Type: application/json'], $headers);
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => json_encode($json),
|
||||
CURLOPT_HTTPHEADER => $hdrs,
|
||||
CURLOPT_TIMEOUT => $timeout,
|
||||
]);
|
||||
$body = curl_exec($ch);
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$err = curl_error($ch);
|
||||
curl_close($ch);
|
||||
return [$code, $body, $err];
|
||||
}
|
||||
Reference in New Issue
Block a user