weezqyd / http-adapters
Unified API for abstracting Various Http clients
Installs: 1 163
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires (Dev)
- codacy/coverage: dev-master
- friendsofphp/php-cs-fixer: ~1.11
- guzzlehttp/guzzle: ~5.0|~6.0
- kriswallsmith/buzz: ~0.10
- mockery/mockery: ^0.9.9
- phpunit/phpunit: ~6.1
This package is auto-updated.
Last update: 2024-12-13 22:16:14 UTC
README
Installation
This library can be found on Packagist. The recommended way to install this is through composer.
Run these commands to install the packages:
$ composer require weezqyd/http-adapters
You then need to install one of the following:
$ composer require kriswallsmith/buzz:~0.10 $ composer require guzzlehttp/guzzle:~5.0 $ composer require guzzlehttp/guzzle:~6.0
GuzzleHttp Adapter
If you use Guzzle, just pass an array of options to the constructor of Http\Adapter\GuzzleHttpAdapter
.
Please refer to Guzzle Documentation. for a full list of possible options
Example
<?php require 'vendor/autoload.php'; use Http\Adapter\GuzzleHttpAdapter; $options = [ // Base URI is used with relative requests 'base_uri' => 'http://httpbin.org', // You can set any number of default request options. 'timeout' => 2.0, // Pass your custom headers 'headers' => [ 'Authorization' => 'your access token', 'X-Foo' => 'Bar' ] ]; // create an adapter with the options $adapter = new GuzzleHttpAdapter($options); // make a get request with the adapter $response = $adapter->get('get?adappter=GuzzleAdapter'); var_dump($response); /* { "args": { "adappter": "GuzzleAdapter" }, "headers": { "headers": { "Authorization": "your access token", "X-Foo": "Bar", "Connection": "close", "Host": "httpbin.org", "User-Agent": "GuzzleHttp/6.2.1 curl/7.47.0 PHP/7.1.6" }, "origin": "0.0.0.0", "url": "https://httpbin.org/get?adappter=GuzzleAdapter" } */