2017 © Pedro Peláez
 

library requester

Requester class to wrap guzzle and retry subscriber

image

pulkitjalan/requester

Requester class to wrap guzzle and retry subscriber

  • Wednesday, March 18, 2015
  • by pulkitjalan
  • Repository
  • 3 Watchers
  • 3 Stars
  • 29,944 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 1 % Grown

The README.md

Requester

Simple Requester class to wrap guzzle and the retry subscriber, (*1)

Build Status Scrutinizer Code Quality Coverage Status License Latest Version Total Downloads, (*2)

This package requires PHP >=5.4, (*3)

Installation

Install via composer - edit your composer.json to require the package., (*4)

"require": {
    "pulkitjalan/requester": "2.*"
}

Then run composer update in your terminal to pull it in., (*5)

Laravel 5

There is a Laravel 5 service provider and facade available., (*6)

Add the following to the providers array in your config/app.php, (*7)

'PulkitJalan\Requester\RequesterServiceProvider'

Next add the following to the aliases array in your config/app.php, (*8)

'Requester' => 'PulkitJalan\Requester\Facades\Requester'

Next run php artisan vendor:publish --provider="pulkitjalan\requester\RequesterServiceProvider" --tag="config" to publish the config file., (*9)

Looking for a Laravel 4 compatible version?

Checkout the 1.0 branch, (*10)

Usage

The requester class has a dependency of guzzle and takes in an instance of guzzle as the first param., (*11)

This package also uses a few guzzle subscribers. https://github.com/guzzle/retry-subscriber for retry functionality and https://github.com/guzzle/log-subscriber for logging., (*12)

Available request methods: get, head, delete, put, patch, post, options, (*13)

<?php

use PulkitJalan\Requester\Requester;
use GuzzleHttp\Client as GuzzleClient;

$requester = new Requester(new GuzzleClient());

// simple get request
$requester->url('example.com')->get();

Altering the default retry behaviour. See retry-subscriber for more info., (*14)

// retry 10 times, with a 1 second wait on a 503 error
$requester->url('example.com')->retry(10)->every(1000)->on([503])->get();

// disabling retry
$requester->url('example.com')->retry(false)->get();

Disabling ssl check, (*15)

// ssl check disabled
$requester->url('example.com')->verify(false)->get();

Use http instead of https, (*16)

// disable https and use http
$requester->url('example.com')->secure(false)->get();

// use http
$requester->url('http://example.com')->get();

Create a Post request, (*17)

// Create a post request
$requester->url('example.com/update/1')->post([
    'body' => [
        'title' => 'some title'
    ]
]);

// Upload a file
$requester->url('example.com/upload')->addFile('/tmp/image.jpg')->post([
    'body' => [
        'title' => 'Some image',
        'description' => 'Some image description'
    ]
]);

Guzzle 5 uses RingPHP and has the added functionality of performing request asynchronously., (*18)

Performing asynchronous requests, (*19)

// Create a post request
$response = $requester->url('example.com')->async(true)->get();

// Use the response asynchronously
$this->response = $response->then(function ($response) {
    return $response->getBody();
});

// Use the response synchronously
$this->response = $response->getBody();

Logging guzzle requests to file. See log-subscriber for more info., (*20)

use PulkitJalan\Requester\Requester;
use GuzzleHttp\Client as GuzzleClient;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('/path/to/your.log', Logger::INFO));

$requester = new Requester(new GuzzleClient());
$requester->addLogger($log);

// request and response logged to file
$requester->url('example.com')->get();

// Use the second param to update the format
$requester = new Requester(new GuzzleClient());
$requester->addLogger($log, 'DEBUG');

The Versions

18/03 2015
26/02 2015

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/pulkitjalan/requester

Requester class to wrap guzzle and retry subscriber

  Sources   Download

MIT

The Requires

 

The Development Requires

curl http guzzle retry

22/12 2014

1.0.0

1.0.0.0 https://github.com/pulkitjalan/requester

Requester class to wrap guzzle and retry subscriber

  Sources   Download

MIT

The Requires

 

The Development Requires

curl http guzzle retry

19/12 2014

0.1.1

0.1.1.0 https://github.com/pulkitjalan/requester

Requester class to wrap guzzle and retry subscriber

  Sources   Download

MIT

The Requires

 

curl http guzzle retry

14/12 2014

0.1.0

0.1.0.0 https://github.com/pulkitjalan/requester

Requester class to wrap guzzle and retry subscriber

  Sources   Download

MIT

The Requires

 

curl http guzzle retry