2017 © Pedro Peláez
 

library httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

image

voku/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  • Saturday, December 23, 2017
  • by voku
  • Repository
  • 2 Watchers
  • 1 Stars
  • 17,873 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 296 Forks
  • 0 Open issues
  • 34 Versions
  • 10 % Grown

The README.md

Build Status codecov.io Codacy Badge Latest Stable Version Total Downloads License Donate to this project using Paypal Donate to this project using Patreon, (*1)

📯 Httpful

Forked some years ago from nategood/httpful + added support for parallel request and implemented many PSR Interfaces: A Chainable, REST Friendly Wrapper for cURL with many "PSR-HTTP" implemented interfaces., (*2)

Features, (*3)

  • Readable HTTP Method Support (GET, PUT, POST, DELETE, HEAD, PATCH and OPTIONS)
  • Custom Headers
  • Automatic "Smart" Parsing
  • Automatic Payload Serialization
  • Basic Auth
  • Client Side Certificate Auth (SSL)
  • Request "Download"
  • Request "Templates"
  • Parallel Request (via curl_multi)
  • PSR-3: Logger Interface
  • PSR-7: HTTP Message Interface
  • PSR-17: HTTP Factory Interface
  • PSR-18: HTTP Client Interface

Examples

<?php

// Make a request to the GitHub API.

$uri = 'https://api.github.com/users/voku';
$response = \Httpful\Client::get($uri, null, \Httpful\Mime::JSON);

echo $response->getBody()->name . ' joined GitHub on ' . date('M jS Y', strtotime($response->getBody()->created_at)) . "\n";
<?php

// Make a request to the GitHub API with a custom
// header of "X-Foo-Header: Just as a demo".

$uri = 'https://api.github.com/users/voku';
$response = \Httpful\Client::get_request($uri)->withAddedHeader('X-Foo-Header', 'Just as a demo')
                                              ->expectsJson()
                                              ->send();

$result = $response->getRawBody();

echo $result['name'] . ' joined GitHub on ' . \date('M jS Y', \strtotime($result['created_at'])) . "\n";
<?php

// BasicAuth example with MultiCurl for async requests.

/** @var \Httpful\Response[] $results */
$results = [];
$multi = new \Httpful\ClientMulti(
    static function (\Httpful\Response $response, \Httpful\Request $request) use (&$results) {
        $results[] = $response;
    }
);

$request = (new \Httpful\Request(\Httpful\Http::GET))
    ->withUriFromString('https://postman-echo.com/basic-auth')
    ->withBasicAuth('postman', 'password');

$multi->add_request($request);
// $multi->add_request(...); // add more calls here

$multi->start();

// DEBUG
//print_r($results);

Installation

composer require voku/httpful

Handlers

We can override the default parser configuration options be registering a parser with different configuration options for a particular mime type, (*4)

Example: setting a namespace for the XMLHandler parser, (*5)

$conf = ['namespace' => 'http://example.com'];
\Httpful\Setup::registerMimeHandler(\Httpful\Mime::XML, new \Httpful\Handlers\XmlMimeHandler($conf));

Handlers are simple classes that are used to parse response bodies and serialize request payloads. All Handlers must implement the MimeHandlerInterface interface and implement two methods: serialize($payload) and parse($response). Let's build a very basic Handler to register for the text/csv mime type., (*6)

<?php

class SimpleCsvMimeHandler extends \Httpful\Handlers\DefaultMimeHandler
{
    /**
     * Takes a response body, and turns it into
     * a two dimensional array.
     *
     * @param string $body
     *
     * @return array
     */
    public function parse($body)
    {
        return \str_getcsv($body);
    }

    /**
     * Takes a two dimensional array and turns it
     * into a serialized string to include as the
     * body of a request
     *
     * @param mixed $payload
     *
     * @return string
     */
    public function serialize($payload)
    {
        // init
        $serialized = '';

        foreach ($payload as $line) {
            $serialized .= '"' . \implode('","', $line) . '"' . "\n";
        }

        return $serialized;
    }
}

\Httpful\Setup::registerMimeHandler(\Httpful\Mime::CSV, new SimpleCsvMimeHandler());

Finally, you must register this handler for a particular mime type., (*7)

\Httpful\Setup::register(Mime::CSV, new SimpleCsvHandler());

After this registering the handler in your source code, by default, any responses with a mime type of text/csv should be parsed by this handler., (*8)

The Versions

23/12 2017

dev-master

9999999-dev http://github.com/voku/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

 

The Development Requires

api curl rest http restful requests

23/12 2017

v0.4.0

0.4.0.0 http://github.com/voku/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

 

The Development Requires

api curl rest http restful requests

10/12 2017

dev-analysis-873adN

dev-analysis-873adN http://github.com/voku/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

 

The Development Requires

api curl rest http restful requests

10/12 2017

v0.3.0

0.3.0.0 http://github.com/voku/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

 

The Development Requires

api curl rest http restful requests

05/08 2017

v0.2.27

0.2.27.0 http://github.com/voku/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

 

The Development Requires

api curl rest http restful requests

12/08 2016

v0.2.26

0.2.26.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

 

The Development Requires

api curl rest http restful requests

30/06 2016

v0.2.25

0.2.25.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

 

The Development Requires

api curl rest http restful requests

06/05 2016

v0.2.24

0.2.24.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

 

The Development Requires

api curl rest http restful requests

06/05 2016

v0.2.23

0.2.23.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

 

The Development Requires

api curl rest http restful requests

26/10 2015

dev-dev

dev-dev http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

The Development Requires

api curl rest http restful requests

26/10 2015

0.2.20

0.2.20.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

The Development Requires

api curl rest http restful requests

08/03 2015

0.2.19

0.2.19.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

The Development Requires

api curl rest http restful requests

24/08 2014

0.2.17

0.2.17.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

The Development Requires

api curl rest http restful requests

19/07 2014

0.2.16

0.2.16.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

The Development Requires

api curl rest http restful requests

21/05 2014

0.2.13

0.2.13.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

The Development Requires

api curl rest http restful requests

21/05 2014

dev-r0.3.0

dev-r0.3.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

The Development Requires

api curl rest http restful requests

18/02 2014

dev-test-server

dev-test-server http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

The Development Requires

api curl rest http restful requests

20/10 2013

0.2.11

0.2.11.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

The Development Requires

api curl rest http restful requests

13/09 2013

0.2.10

0.2.10.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

The Development Requires

api curl rest http restful requests

12/09 2013

0.2.9

0.2.9.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

The Development Requires

api curl rest http restful requests

01/08 2013

0.2.8

0.2.8.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

The Development Requires

api curl rest http restful requests

30/07 2013

0.2.7

0.2.7.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

The Development Requires

api curl rest http restful requests

05/07 2013

0.2.6

0.2.6.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

The Development Requires

api curl rest http restful requests

28/06 2013

0.2.5

0.2.5.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

api curl rest http restful requests

05/03 2013

0.2.3

0.2.3.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

api curl rest http restful requests

27/02 2013

0.2.2

0.2.2.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

api curl rest http restful requests

19/02 2013

0.2.1

0.2.1.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

api curl rest http restful requests

25/01 2013

0.2.0

0.2.0.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

api curl rest http restful requests

15/09 2012

0.1.7

0.1.7.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

api curl rest http restful requests

30/08 2012

0.1.6

0.1.6.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

api curl rest http restful requests

20/06 2012

0.1.5

0.1.5.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

api curl rest http restful requests

13/06 2012

0.1.4

0.1.4.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

api curl rest http restful requests

09/05 2012

0.1.2

0.1.2.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

api curl rest http restful requests

14/04 2012

0.1.0

0.1.0.0 http://github.com/nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-curl *

 

curl rest http restful