PHP code example of matthewerskine / guzzle

1. Go to this page and download the library: Download matthewerskine/guzzle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

matthewerskine / guzzle example snippets





use MatthewErskine\Guzzle\Client;

class FruitService extends Client
{
    public function getFruits()
    {
        // {"data": [{"title": "banana"}, {"title": "apple"}]}
        return $this->respond(
            $this->getHttpClient()->get($this->getUrl().'/bananas')
        );
    }
}




class FruitRepository
{
    ...

    public function giveMeABanana()
    {
        foreach ($this->fruitService->getFruits() as $fruit) {
            if ($fruit['title'] == 'banana') {
                return $fruit;
            }
        }
    }
}