songshenzong / http-client
extension PHP HTTP client for Guzzle
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 1 535
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.6
- guzzlehttp/guzzle: ^6.3
- songshenzong/support: ^1.0.0
Requires (Dev)
- laravel/framework: 5.6.*
- phpunit/phpunit: ~7.0
This package is auto-updated.
Last update: 2021-12-08 18:46:12 UTC
README
HttpClient is a extension PHP HTTP client for Guzzle, you can use all of Guzzle's methods and advantages are:
- Use all of Guzzle's methods statically.
- Access the
Response
as an array or object. - IDE tips are more friendly.
- Other methods, such as
uri
. - Support Laravel, such as
Queues
,Notifications
. - Always sync with Guzzle.
$uri = HttpClient::uri('https://packagist.org/search.json', ['q' => 'songshenzong']); // https://packagist.org/search.json?q=songshenzong $response = HttpClient::request('GET', $uri); // $response = HttpClient::get($uri); // $response = HttpClient::post($uri); // $response = HttpClient::put($uri); // $response = HttpClient::delete($uri); print_r($response->toArray()); // Array // ( // [results] => Array // ) echo $response['total']; // 12 echo $response->total; // 12 var_dump($response->isJson()); // bool(true) var_dump($response->isXml()); // bool(false) var_dump($response->isSerialized()); // bool(false) print_r($response->serialize()); // s:2732:"{"results":[{"name":"songshenzong... var_dump($response->unserialize()); // false | object | array echo $response->getStatusCode(); // 200 echo $response->getHeaderLine('content-type'); // application/json echo $response->getBody(); // {"results":[{"name":"songshenzong...} // Send an asynchronous request. $promise = HttpClient::requestAsync('GET', $uri)->then(function ($response) { $response = new \Songshenzong\HttpClient\Response($response); echo $response['total']; }); $promise->wait();
Installation
Installing the latest stable version:
composer require songshenzong/http-client
You can update using composer:
composer update
Laravel Queues
CurlJob::dispatch('GET', 'https://packagist.org/search.json?q=songshenzong'); CurlJob::dispatchNow('GET', 'https://packagist.org/search.json?q=songshenzong');
Laravel Notifications
Notification::send($user, new CurlNotification('GET', 'https://packagist.org/search.json?q=songshenzong'));
Example
/** * Get the notification's delivery channels. * * @param $notifiable * * @return array */ public function via($notifiable): array { return [HttpClientChannel::class]; } /** * @param $notifiable * * @return mixed */ public function toHttp($notifiable) { return HttpClient::request('GET', 'https://packagist.org/search.json?q=songshenzong'); }
Documentation
HttpClient is a extension PHP HTTP client for Guzzle, you can use all of Guzzle's methods.
Support
For answers you may not find in the Wiki, avoid posting issues. Feel free to ask for support on Songshenzong.com
License
This package is licensed under the BSD 3-Clause license.