Skip to content

Instantly share code, notes, and snippets.

@abugraokkali
Last active August 13, 2021 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abugraokkali/8d99177a7af4daa62b2d63e3941fdd88 to your computer and use it in GitHub Desktop.
Save abugraokkali/8d99177a7af4daa62b2d63e3941fdd88 to your computer and use it in GitHub Desktop.

Guzzle

Guzzle, HTTP isteklerini göndermeyi ve web servisleriyle entegre olmayı kolaylaştıran bir PHP HTTP istemcisidir.

  • İstemci Oluşturma

Base URI'ye sahip bir GuzzleHttp\Client objesi oluşturun.

use GuzzleHttp\Client;

$client = new GuzzleHttp\Client(
					
	['base_uri' => 'IP:PORT/']
);
  • İstek Gönderme

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');
  • Yanıtı İşleme ve Tablo Haline Getirme

İ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"]
 ]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment