2017 © Pedro Peláez
 

library http-client

Simple HTTP-client, wrapper for Guzzle and rmccue/requests

image

jbzoo/http-client

Simple HTTP-client, wrapper for Guzzle and rmccue/requests

  • PHP
  • 6 Dependents
  • 1 Suggesters
  • 1 Forks
  • 2 Open issues
  • 10 Versions
  • 14 % Grown

The README.md

JBZoo / Http-Client

CI Coverage Status Psalm Coverage Psalm Level CodeFactor
Stable Version Total Downloads Dependents GitHub License, (*1)

Just make HTTP requests in one line and don't care about terrible syntax of GuzzleHttp ;), (*2)

Install

composer require guzzlehttp/guzzle --no-update # Recommended, but not required
composer require jbzoo/http-client

Usage

use JBZoo\HttpClient\HttpClient;

// Configure client (no options required!)
$httpClient = new HttpClient([
    'auth'            => [          // Simple HTTP auth
        'http-user-name',
        'http-password'
    ],
    'headers'         => [          // Your custom headers
        'X-Custom-Header' => 42,
    ],
    'driver'          => 'auto',    // (Auto|Guzzle5|Guzzle6|Rmccue)
    'timeout'         => 10,        // Wait in seconds
    'verify'          => false,     // Check cert for SSL
    'exceptions'      => false,     // Show exceptions for statuses 4xx and 5xx
    'allow_redirects' => true,      // Show real 3xx-header or result?
    'max_redirects'   => 10,        // How much to redirect?
    'user_agent'      => "It's me", // Custom UserAgent
]);

// Just request
$response = $httpClient->request('http://my.site.com/', [
    'key-1' => 'value-1',
    'key-2' => 'value-2'
], 'post');

Methods of response, (*3)

// Get code
$code = $response->getCode();
$code = $response->code;
$code = $response['code'];

// Get headers
$headers = $response->getHeaders();
$headers = $response->headers;
$headers = $response['headers'];
$header  = $response->getHeader('X-Custom-Header-Response');
$header  = $response->find('headers.x-custom-header-response', 'default-value', 'trim');

// Get body
$body = $response->getBody();
$body = $response->body;
$body = $response['body'];

// Get body like JSON (see JBZoo/Data lib)
$json = $response->getJSON();
$value = $json->get('key', 'default', 'trim');
$value = $json->find('key.nested', 'default', 'trim');

Asynchronous requests (curl_multi_* for parallels)

use JBZoo\HttpClient\HttpClient;

$httpClient = new HttpClient();

$results = $httpClient->multiRequest(array(
    'request_0' => 'http://mockbin.org/request',

    'request_1' => ['http://mockbin.org/request', [
        'args' => ['key' => 'value']
    ]],

    'request_2' => ['http://mockbin.org/request', [
        'method' => 'post',
        'args'   => ['key' => 'value'],
        'headers'         => [
            'X-Custom-Header' => 42,
        ],
        'timeout'         => 10,
        'verify'          => false,
        'exceptions'      => false,
        'allow_redirects' => true,
        'max_redirects'   => 10, 
        'user_agent'      => 'JBZoo/Http-Client v1.x-dev'
    ]]
]);

$results['request_0']->getBody(); 
$results['request_1']->getBody(); 
$results['request_2']->getBody();

Unit tests and check code style

make update
make test-all

License

MIT, (*4)

The Versions

23/11 2017

dev-master

9999999-dev

Simple HTTP-client, wrapper for Guzzle and rmccue/requests

  Sources   Download

MIT

The Requires

 

The Development Requires

curl https http request client guzzle requests guzzlehttp rmccue

23/11 2017

1.2.1

1.2.1.0

Simple HTTP-client, wrapper for Guzzle and rmccue/requests

  Sources   Download

MIT

The Requires

 

The Development Requires

curl https http request client guzzle requests guzzlehttp rmccue

17/11 2017

1.2.0

1.2.0.0

Simple HTTP-client, wrapper for Guzzle and rmccue/requests

  Sources   Download

MIT

The Requires

 

The Development Requires

curl https http request client guzzle requests guzzlehttp rmccue

15/06 2017

1.1.3

1.1.3.0

Simple HTTP-client, wrapper for Guzzle and rmccue/requests

  Sources   Download

MIT

The Requires

 

The Development Requires

curl https http request client guzzle requests guzzlehttp rmccue

06/08 2016

1.1.2

1.1.2.0

Simple HTTP-client, wrapper for Guzzle and rmccue/requests

  Sources   Download

MIT

The Requires

 

The Development Requires

curl https http request client guzzle requests guzzlehttp rmccue

06/08 2016

dev-develop

dev-develop

Simple HTTP-client, wrapper for Guzzle and rmccue/requests

  Sources   Download

MIT

The Requires

 

The Development Requires

curl https http request client guzzle requests guzzlehttp rmccue

01/08 2016

1.1.1

1.1.1.0

Simple HTTP-client, wrapper for Guzzle and rmccue/requests

  Sources   Download

MIT

The Requires

 

The Development Requires

curl https http request client guzzle requests guzzlehttp rmccue

01/08 2016

1.1.0

1.1.0.0

Simple HTTP-client, wrapper for Guzzle and rmccue/requests

  Sources   Download

MIT

The Requires

 

The Development Requires

curl https http request client guzzle requests guzzlehttp rmccue

31/07 2016

1.0.1

1.0.1.0

Simple HTTP-client, wrapper for Guzzle and rmccue/requests

  Sources   Download

MIT

The Requires

 

The Development Requires

curl https http request client guzzle requests guzzlehttp rmccue

31/07 2016

1.0.0

1.0.0.0

Simple HTTP-client, wrapper for Guzzle and rmccue/requests

  Sources   Download

MIT

The Requires

 

The Development Requires

curl https http request client guzzle requests guzzlehttp rmccue