Skip to content

Releases: phpro/http-tools

Version 2.5.0

09 Sep 12:54
2.5.0
69018d6
Compare
Choose a tag to compare

What's Changed

  • Implement http exception to be compatible with HTTP mock client by @veewee in #41

Full Changelog: 2.4.0...2.5.0

Version 2.4.0

06 Sep 10:51
2.4.0
ee9ca4b
Compare
Choose a tag to compare

What's Changed

ℹ️

Bump to PSL 3 implies bumping PHP to >8.2
People on 8.1 can still use older versions of this package. (it's all pretty stable right now)

Full Changelog: 2.3.0...2.4.0

Version 2.3.0

24 Nov 08:18
2.3.0
e848144
Compare
Choose a tag to compare

What's Changed

Full Changelog: 2.2.0...2.3.0

Version 2.2.0

13 Nov 09:12
2.2.0
a829e9c
Compare
Choose a tag to compare

What's Changed

  • Added method romFormData to BinaryDownloadPreset to easily use with form data/requests by @stefliekens in #38

Full Changelog: 2.1.2...2.2.0

Version 2.1.2

09 Nov 18:58
2.1.2
2464a24
Compare
Choose a tag to compare

What's Changed

  • Fix broken content-type for good by @veewee in #37

Full Changelog: 2.1.1...2.1.2

Version 2.1.1

09 Nov 13:53
2.1.1
4ff5a2a
Compare
Choose a tag to compare

What's Changed

Full Changelog: 2.1.0...2.1.1

Version 2.1.0

09 Nov 13:02
2.1.0
b8501fb
Compare
Choose a tag to compare

What's Changed

  • Introduce a BinaryFile decoder by @veewee in #32
  • Introduce multipart encoder by @veewee in #33
  • Improve error handling of optional dependencies by @veewee in #34
  • Add uploads/downloads docs by @veewee in #35

This release focusses on uploading and downloading files;

Download

use Phpro\HttpTools\Encoding\Binary\BinaryFile;
use Phpro\HttpTools\Transport\Presets\BinaryDownloadPreset;

$transport = BinaryDownloadPreset::create($client, $uriBuilder);
$binaryFile = $transport(
    new YourDownloadRequest('GET', '/some/file'),
);

assert($binaryFile instanceof BinaryFile);
var_dump(
    $binaryFile->stream(),
    $binaryFile->fileSizeInBytes(),
    $binaryFile->hash(),
    $binaryFile->extension(),
    $binaryFile->mimeType(),
    $binaryFile->fileName(),
);

This decoder will try to parse some information from the Response headers and stream:

  • The stream body can be used to tell the size in bytes of the response or to calculate an MD5 (or other algorithm's) hash.
  • Content-Type: could be used to guess the mime-type
  • Content-Disposistion: could result in guessing the filename, extension and/or mime-type.
  • Content-Length: could be used to guess the size in bytes of the response.

The decoder is highly configurable, meaning you can alter the way it guesses specific properties or opt-out on intenser logic like calculating a md5 hash.

Upload

use Phpro\HttpTools\Encoding\Json\JsonDecoder;
use Phpro\HttpTools\Encoding\Mime\MultiPartEncoder;
use Phpro\HttpTools\Transport\EncodedTransportFactory;
use Symfony\Component\Mime\Part\DataPart;
use Symfony\Component\Mime\Part\Multipart\FormDataPart;
use Phpro\HttpTools\Request\Request;

$transport = EncodedTransportFactory::create(
    $client,
    $uriBuilder,
    MultiPartEncoder::createWithAutodiscoveredPsrFactories(),
    JsonDecoder::createWithAutodiscoveredPsrFactories()
);

$jsonData = $transport(
    new YourUploadRequest('POST', '/some/endpoint', new FormDataPart([
        'name' => 'Jos bos',
        'profile-pic' => DataPart::fromPath('/my-profile-pic.jpg')
    ])),
);

Note: If you wish not to use symfony/mime for uploading files, you could use guzzle/psr7's MultipartStream with the existing StreamEncoder option:

use GuzzleHttp\Psr7\MultipartStream;
use Phpro\HttpTools\Encoding\Json\JsonDecoder;
use Phpro\HttpTools\Encoding\Stream\StreamEncoder;
use Phpro\HttpTools\Transport\EncodedTransportFactory;
use Symfony\Component\Mime\Part\DataPart;
use Symfony\Component\Mime\Part\Multipart\FormDataPart;
use Phpro\HttpTools\Request\Request;

$transport = EncodedTransportFactory::create(
    $client,
    $uriBuilder,
    StreamEncoder::createWithAutodiscoveredPsrFactories(),
    JsonDecoder::createWithAutodiscoveredPsrFactories()
);

$multiPartStream = new MultipartStream($parts)
$jsonData = $transport(
    new YourUploadRequest('POST', '/some/endpoint', $multiPartStream),
);

Full Changelog: 2.0.0...2.1.0

Version 2.0.0

29 Sep 11:19
2.0.0
Compare
Choose a tag to compare

Upgrading

This new version removes the async implementation around amp v2 and httplug promises.
The new suggested way of performing async calls is by using a fiber based PSR-18 HTTP client.

Upgrading async transports

Your async transports and handlers can be transformed to regular sync implementations.
You will need to provide a fiber based PSR-18 client as documented.
This client can then be used to run HTTP calls in parallel, using either reactphp or amphp v3.

$client = new AsyncPsr18Browser(new Browser());
$transport = JsonPreset::create($client, new TemplatedUriBuilder());
$handler = new FetchSomething($transport);

$run = fn($id) => async(fn () => $handler(new FetchRequest($id)));
$things = await(parallel([
    $run(1),
    $run(2),
    $run(3),
]));

Upgrading sync transports

Previously, all presets had both a sync() and async() named constructor.
Since this package now doesn't distinguish this anymore, there is only one create() named constructor.
You'll need to replace all occurences.
For example:

-  JsonTransport::sync(...);
+  JsonTransport::create(...);

-  JsonTransport::async(...);
+  JsonTransport::create(...);

-  RawTransport::async(...);
+  RawTransport::create(...);

-  RawTransport::async(...);
+  RawTransport::create(...);

What's Changed

  • Open up this package for fibers by @veewee in #31

Full Changelog: 1.4.1...2.0.0

Version 1.4.1

16 Feb 08:34
1.4.1
427afe9
Compare
Choose a tag to compare

What's Changed

Full Changelog: 1.4.0...1.4.1

Version 1.4.0

25 Nov 11:40
1.4.0
7c667fe
Compare
Choose a tag to compare

What's Changed

Full Changelog: 1.3.0...1.4.0