Guzzle, HTTP isteklerini göndermeyi ve web servisleriyle entegre olmayı kolaylaştıran bir PHP HTTP istemcisidir.
Base URI'ye sahip bir GuzzleHttp\Client objesi oluşturun.
use GuzzleHttp\Client;
$client = new GuzzleHttp\Client(
['base_uri' => 'IP:PORT/']
);
Oluşturduğunuz GuzzleHttp\Client nesnesini kullanarak istek gönderebilirsiniz.
http://IP:PORT/users adresine aşağıdaki satırı kullanarak istek gönderin.
$response = $client->request('GET', 'users');
İstekten gelen yanıtı işleyip tablo haline getirin.
$response = json_decode($response->getBody()->getContents());
$array = (array) $response->data;
$data = [];
foreach($array as $element){
$data[] = [
"name" => $element->{'name'},
"age" => $element->{'age'},
"city" => $element->{'city'}
];
}
return view('table', [
"value" => $data,
"title" => ["ISIM","YAS","SEHIR"],
"display" => ["name","age","city"]
]);