All Projects → PhpGt → Fetch

PhpGt / Fetch

Licence: MIT license
Asynchronous HTTP client with promises.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to Fetch

Wretch
A tiny wrapper built around fetch with an intuitive syntax. 🍬
Stars: ✭ 2,285 (+7779.31%)
Mutual labels:  fetch, promise, http-client
Create Request
Apply interceptors to `fetch` and create a custom request function.
Stars: ✭ 34 (+17.24%)
Mutual labels:  fetch, promise, http-client
Node Fetch
A light-weight module that brings the Fetch API to Node.js
Stars: ✭ 7,176 (+24644.83%)
Mutual labels:  fetch, promise, http-client
Fetcher Ts
Type-safe wrapper around Fetch API
Stars: ✭ 87 (+200%)
Mutual labels:  fetch, http-client
Ky
🌳 Tiny & elegant JavaScript HTTP client based on the browser Fetch API
Stars: ✭ 7,047 (+24200%)
Mutual labels:  fetch, http-client
Cross Fetch
Universal WHATWG Fetch API for Node, Browsers and React Native.
Stars: ✭ 1,063 (+3565.52%)
Mutual labels:  fetch, http-client
Ky Universal
Use Ky in both Node.js and browsers
Stars: ✭ 421 (+1351.72%)
Mutual labels:  fetch, http-client
Vue2 Element
基于vue2 + vue-router2 + element-ui + vuex2 + fetch + webpack2 企业级后台管理系统最佳实践
Stars: ✭ 112 (+286.21%)
Mutual labels:  fetch, promise
Mfetch
mfetch will provide you with a strong ability to request resource management
Stars: ✭ 90 (+210.34%)
Mutual labels:  fetch, promise
Fetch Plus
🐕 Fetch+ is a convenient Fetch API replacement with first-class middleware support.
Stars: ✭ 116 (+300%)
Mutual labels:  fetch, promises
fetchye
✨ If you know how to use Fetch, you know how to use Fetchye [fetch-yae]. Simple React Hooks, Centralized Cache, Infinitely Extensible.
Stars: ✭ 36 (+24.14%)
Mutual labels:  fetch, promise
promiviz
Visualize JavaScript Promises on the browser. Visualize the JavaScript Promise APIs and learn. It is a playground to learn about promises faster, ever!
Stars: ✭ 79 (+172.41%)
Mutual labels:  promises, promise
fennch
Modern fetch-based axios-like HTTP client for the browser and node.js
Stars: ✭ 12 (-58.62%)
Mutual labels:  fetch, http-client
Fetch
A window.fetch JavaScript polyfill.
Stars: ✭ 25,118 (+86513.79%)
Mutual labels:  fetch, promise
market-pricing
Wrapper for the unofficial Steam Market Pricing API
Stars: ✭ 21 (-27.59%)
Mutual labels:  promises, promise
Php Fetch
A simple, type-safe, zero dependency port of the javascript fetch WebApi for PHP
Stars: ✭ 95 (+227.59%)
Mutual labels:  fetch, http-client
Gretchen
Making fetch happen in TypeScript.
Stars: ✭ 301 (+937.93%)
Mutual labels:  fetch, http-client
Redux Requests
Declarative AJAX requests and automatic network state management for single-page applications
Stars: ✭ 330 (+1037.93%)
Mutual labels:  fetch, http-client
Mande
600 bytes convenient and modern wrapper around fetch
Stars: ✭ 154 (+431.03%)
Mutual labels:  fetch, promise
bluff
🙏 Promise A+ implementation
Stars: ✭ 14 (-51.72%)
Mutual labels:  promises, promise

Asynchronous HTTP client with promises.

Asynchronous HTTP client, PSR-7 compatible implementation of the Fetch Standard which defines requests, responses, and the process that binds them: fetching.

This repository provides a PHP-HTTP Client Implementation for standardised HTTP interoperability.

See also, the JavaScript implementation that ships as standard in all modern browsers.


Build status Code quality Code coverage Current version PHP.Gt/Fetch documentation

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;
});

Example usage: HTTPlug PHP-HTTP Client & Asynchronous Client

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

$slowRequest = new Request("GET", "http://slow.example.com");
$fastRequest = new Request("GET", "http://fast.example.com");

// Send the slow request asynchronously (returns a Http\Promise)
$http->sendAsyncRequest($slowRequest)
->then(function(ResponseInterface $response) {
	echo $response->getBody();
});

// Perform fast request synchronously (block until response ready)
$response = $http->sendRequest($fastRequest);

// Wait for any asynchronous requests to be completed.
$http->wait();

For more extensive examples, check out the code in the example directory.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].