- FEATURES
- Autoload
- Class Reflection
- Magic Methods
- Exceptions
- Late Static Binding
- SPL
- PHPUNIT
- PHAR
- COMPOSER
- Carbon
-
Guzzle
- Faker
- Math
- Requests
- DESIGN PATTERNS
- Singleton Pattern
- Observer Pattern
- Strategy Pattern
- Dependency Injection
- Middleware
- Service Layer
- Registry
- SYMFONY
- Routes
- Annotations
- Flex
- Controllers
- Doctrine
- Templating
- VERSIONS
- Php7.4
- Php8.0
- SECURITY
- Filter Input
- Remote Code Injection
- Sql Injection
- Session Fixation
- File Uploads
- Cross Site Scripting
- Spoofed Forms
- CSRF
- Session Hijacking
- MODERN PHP
- Composer
- Autoloader
- Package
- Releases
- Generators
- Dependency Injection
- Middleware
- CUSTOM FRAMEWORK
- App
- Http Foundation
- Front Controller
- Routing
- Render Controller
- Resolver
- SoC
- FRAMEWORKS
- Slim
- Symfony V5
- Laravel V8
- Laminas V3
- Codeigniter V4
PHP PAGES - LEVEL 2
Guzzle
Guzzle is a HTTP client library for PHP, initially a wrapper library around cURL. It evolved to a transport agnostic PSR-7 compatible library. composer require guzzlehttp/guzzle
require __DIR__ . '/vendor/autoload.php';
$client = new GuzzleHttp\Client();
$response = $client->request('GET', 'http://httpbin.org/get');
$json = json_decode($response->getBody());
echo $json->origin; // 188.27.97.4
Guzzle API
The main benefits of using Guzzle over cURL is the API it offers. Guzzle is an abstraction layer for http request. It uses cURL by default but you can use any other http client that you want.
/**
* Send an asynchronous request:
*/
require __DIR__ . '/vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
$client = new Client();
$request = new Request('GET', 'https://api.github.com/repos/guzzle/guzzle');
$promise = $client->sendAsync($request)->then(
function ($response) {
echo 'Response is completed! ';
echo 'Response: ' . json_decode($response->getBody())->{'full_name'};
}
);
$promise->wait();
// Response is completed!
// Response: guzzle/guzzle
Questions and answers:
Clink on Option to Answer
1. Guzzle is an abstraction layer for:
- a) http requests
- b) cURL