LaravelPackages.net
Acme Inc.
Toggle sidebar
johnathan-smith/xttp

A guzzle wrapper with typehints and syntactic sugar.

13
1
1.0.3
About johnathan-smith/xttp

johnathan-smith/xttp is a Laravel package for a guzzle wrapper with typehints and syntactic sugar.. It currently has 1 GitHub stars and 13 downloads on Packagist (latest version 1.0.3). Install it with composer require johnathan-smith/xttp. Discover more Laravel packages by johnathan-smith or browse all Laravel packages to compare alternatives.

Last updated

xttp

A guzzle wrapper with typehints and syntactic sugar.

Regular use is simple:

<?php
use JohnathanSmith\Xttp\Xttp;

/** @var \JohnathanSmith\Xttp\XttpResponseWrapper $xttpResponse */

$xttpResponse = Xttp::post('https://johnathansmith.com', ['form_params' => ['foo' => 'bar'], 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded']]);

// You may also do get, put, patch, delete.

There is also a package for Laravel.

After making the request you will get an instance of XttpResponse. This has a lot of syntactic sugar, for example:

  • Getting header/s
  • Getting response status and info
  • Returning JSON or body
  • Getting URL
  • Cookies

One of the ways that this package shines is that it is set up to be very friendly with Unit testing. You can also easily create a longer version from above with an large amount of granular detail. You can do this on XttpPending the object. With this we can:

  • Add Cookies/Headers/Options
  • Add or prepend Request/Response/Retry/Other middleware
  • Guzzle History and/or Mock handlers
  • Authorization
  • Guzzle Client Construction
<?php
use JohnathanSmith\Xttp\XttpPending;

$response = XttpPending::new()
->setUrl(// url)
->setMethod(// method)
->withHeaders(['X-Foo' => 'Bar'])
->asJson()
->send();

Xttp was inspired by Adam Wathan's zttp. A special thanks to the maintainers of Guzzle.

Star History Chart