Adding PHP client

This commit is contained in:
debian 2023-01-06 17:44:47 +01:00
parent 29b7a1e134
commit e67de50ea7

67
src/kratos.php Normal file
View file

@ -0,0 +1,67 @@
<?php
echo '<!DOCTYPE html>
<html>
<body>
<h2>Mirabel</h2>
<form action="/kratos.php" method="GET">
<input type="text" id="search" name="search" value="lettre"><br>
<input type="submit" value="Rechercher">
</form>
</body>
</html>';
function CallAPI($method, $url, $data = false)
{
$curl = curl_init();
switch ($method)
{
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
case "PUT":
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
default:
if ($data)
$url = sprintf("%s?%s", $url, http_build_query($data));
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
// Search titre
if (isset($_GET["search"]) && !empty($_GET["search"])){
$url = 'http://hephaistos.efrei:8080/api/titre/' . $_GET["search"];
$result = CallAPI('GET', $url, false);
echo $result;
$response = json_decode($result, true);
$errors = $response['response']['errors'];
$data = $response['response']['data'];
}
?>