Asynchronous HTTP client with promises.
Full Changelog: https://github.com/PhpGt/Fetch/compare/v1.1.1...v1.2.0
This release refactors the web API classes used in this repository into the upstream phpgt/http library.
Full Changelog: https://github.com/PhpGt/Fetch/compare/v1.1.0...v1.1.1
This feature removes any third part implementations of the underlying Promise implementation.
Full Changelog: https://github.com/PhpGt/Fetch/compare/v1.0.1...v1.1.0
Type-safe functions have been added to the Json
object, along with enhanced iterator functions. This release is being made ready for the work starting on v2, where PhpGt's Async functions are integrated as opposed to React's.
The last few weeks have seen many PHP.Gt repositories reach stable release, and as Fetch was dependent on a few core repositories, is has finally got a clear dependency tree of stable repositories through Composer.
The 0.7.x releases mark the final steps towards stable release, implementing the other types of response, starting with the blob
type.
Implementing the different types has outlined a potential new repository for PhpGt: WebAPI
, which would be a collection of the standard objects that make up the W3C WebAPI, such as Blob, ArrayBuffer, etc. For now, these exist within Fetch, because there doesn't seem to be much use of reusing them on the server elsewhere... yet.
Calling the fetch method with a PSR-7 RequestInterface is now possible, with the library converting the properties of the Request object to the corresponding CURLOPT settings.
Along with some working example code in /example, the main feature added to this development release is the ability to resolve JSON responses, as with the client-side fetch API.
This means that if you are expecting a response to be a JSON document, returning $response->json()
will resolve a promise that will receive the pre-decoded JSON object for use.
Check out example/02-post-request.php
for example code showcasing this.
While using this library in real world tests, it seems that a lot of APIs (Github's for example) require a useragent header to be sent with a request.
It's possible to set your own headers, but this shouldn't be a required step, as just using curl
on the commandline or from PHP automatically sets their default useragent, so now this library does too.
The issue that was being tracked by #28 is now resolved. The response of a promise's fulfilment could also be a promise, which was in turn not being fulfilled.
Now a recursive check is made to ensure all promises are called in the current chain.