rymanalu / http
Simple HTTP Client library powered by Guzzle.
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
This package provides a new way to use GuzzleHttp package.
Installation
Install this package via the Composer package manager:
composer require rymanalu/http
Usage
Case: we want to call http://foo.com/bar
API.
Steps:
- Create a new endpoint by extending
Rymanalu\Http\Endpoint
. For example:
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'; }
- Create a new
Rymanalu\Http\Client
instance:
$http = new Rymanalu\Http\Client('http://foo.com');
- Call the
call
method in theRymanalu\Http\Client
instance by giving theBarEndpoint
instance:
$endpoint = new BarEndpoint; // or `new BarEndpoint($anArrayOfGuzzleOptions)` $response = $http->call($endpoint);
- The
$response
will be an object ofRymanalu\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