rymanalu / http
由Guzzle驱动的简单HTTP客户端库。
v0.2.1
2017-03-30 11:29 UTC
Requires
- php: >=5.5.9
- guzzlehttp/guzzle: ^6.2
- psr/http-message: ^1.0
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~4.8
README
此包提供了一种新的使用GuzzleHttp包的方式。
安装
通过Composer包管理器安装此包
composer require rymanalu/http
用法
案例:我们想要调用http://foo.com/bar API。
步骤
- 通过扩展
Rymanalu\Http\Endpoint创建一个新的端点。例如
use Rymanalu\Http\Endpoint; class BarEndpoint extends Endpoint { /** * The endpoint's URI. * * @var string */ protected $uri = 'bar'; /** * The endpoint's method. * * @var string */ protected $method = 'POST'; }
- 创建一个新的
Rymanalu\Http\Client实例
$http = new Rymanalu\Http\Client('http://foo.com');
- 通过传递
BarEndpoint实例,在Rymanalu\Http\Client实例中调用call方法
$endpoint = new BarEndpoint; // or `new BarEndpoint($anArrayOfGuzzleOptions)` $response = $http->call($endpoint);
$response将是一个Rymanalu\Http\Response对象
// Check if the calls is successful by the response code... $response->isSuccessful(); // `true` or `false` // Get the response body... $response->getBody(); // object of `stdClass` $response->getBody(true); // array