2017 © Pedro Peláez
 

library fetch

Asynchronous HTTP client with promises.

image

phpgt/fetch

Asynchronous HTTP client with promises.

  • Monday, July 30, 2018
  • by g105b
  • Repository
  • 2 Watchers
  • 6 Stars
  • 939 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 8 Open issues
  • 10 Versions
  • 15 % Grown

The README.md

Asynchronous HTTP client with promises.

Asynchronous HTTP client, implementation of the Fetch Standard which defines requests, responses, and the process that binds them: fetching., (*1)

See also, the JavaScript implementation that ships as standard in all modern browsers., (*2)


Build status Code quality Code coverage Current version PHP.Gt/Fetch documentation , (*3)

Example usage: compute multiple HTTP requests in parallel, using fetch

<?php
$http = new Gt\Fetch\Http();

// Rather than creating the request now, `fetch` returns a Promise, 
// for later resolution with the BodyResponse.
$http->fetch("http://example.com/api/something.json")
->then(function(BodyResponse $response) {
// The first Promise resolves as soon as a response is received, even before
// the body's content has completed downloading.
    if(!$response->ok) {
        echo "Looks like there was a problem. Status code: "
            . $response->getStatusCode() . PHP_EOL;
        return null;
    }

// Within this Promise callback, you have access to the body stream, but
// to access the contents of the whole body, return a new Promise here:
    return $response->json();
})
->then(function(Json $json) {
// The second Promise resolves once the whole body has completed downloading.
    echo "Got JSON result length "
        . count($json->results)
        . PHP_EOL;

// Notice that type-safe getters are available on all Json objects:
    echo "Name of first result: "
        . $json->results[0]->getString("name")
        . PHP_EOL;
});

// A third request is made here to show a different type of body response:
$http->fetch("http://example.com/something.jpg")
->then(function(BodyResponse $response) {
    return $response->blob();
})
->then(function($blob) {
    echo "Got JPG blob. Saving file." . PHP_EOL;
    file_put_contents("/tmp/something.jpg", $blob);
});

// Once all Promises are registered, all HTTP requests can be initiated in
// parallel, with the callback function triggered when they are all complete. 
$http->all()->then(function() {
    echo "All HTTP calls have completed!" . PHP_EOL;
});

For more extensive examples, check out the code in the example directory., (*4)

The Versions

30/07 2018

dev-master

9999999-dev

Asynchronous HTTP client with promises.

  Sources   Download

MIT

The Requires

 

The Development Requires

curl fetch ajax http asynchronous async post curl_multi get xmlhttprequest

04/06 2017

dev-16-psr7

dev-16-psr7

Asynchronous HTTP client with promises for PHP 7 applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

curl fetch ajax http asynchronous async post curl_multi get xmlhttprequest httplug

01/06 2017

v0.3.0

0.3.0.0

Asynchronous HTTP client with promises for PHP 7 applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

curl fetch ajax http asynchronous async post curl_multi get xmlhttprequest httplug

10/11 2016

v0.2.1

0.2.1.0

Asynchronous HTTP client with promises for PHP 7 applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

curl fetch ajax http asynchronous async post curl_multi get xmlhttprequest

08/10 2016

v0.2.0

0.2.0.0

Asynchronous HTTP client with promises for PHP 7 applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

curl fetch ajax http asynchronous async post curl_multi get xmlhttprequest

08/10 2016

dev-develop

dev-develop

Asynchronous HTTP client with promises for PHP 7 applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/10 2016

v0.1.1

0.1.1.0

Asynchronous HTTP client with promises for PHP 7 applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

04/10 2016

v0.1.0

0.1.0.0

Asynchronous HTTP client with promises for PHP 7 applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

01/10 2016

v0.0.2

0.0.2.0

Asynchronous HTTP client with promises for PHP 7 applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

01/10 2016

v0.0.1

0.0.1.0

Asynchronous HTTP client with promises for PHP 7 applications.

  Sources   Download

MIT

The Requires

 

The Development Requires