2017 © Pedro Peláez
 

library http-adapters

Unified API for abstracting Various Http clients

image

weezqyd/http-adapters

Unified API for abstracting Various Http clients

  • Thursday, February 22, 2018
  • by weezqyd
  • Repository
  • 1 Watchers
  • 0 Stars
  • 852 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 22 % Grown

The README.md

Http Adapters

Build Status Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Installation

This library can be found on Packagist. The recommended way to install this is through composer., (*2)

Run these commands to install the packages:, (*3)

$ composer require weezqyd/http-adapters

You then need to install one of the following:, (*4)

$ 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, (*5)

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"
}
 */

The Versions

11/07 2017