programster/guzzle-wrapper

A library to make it easier to use Guzzle for sending HTTP requests.

1.1.0 2020-12-28 17:11 UTC

This package is auto-updated.

Last update: 2024-04-05 16:38:05 UTC


README

A library that wraps around Guzzle in order to make it easier to send HTTP requests. If you need to do anything more complicated, then you can just get the guzzle objects within.

Example Usage

$request = new Programster\GuzzleWrapper\Request(
    Programster\GuzzleWrapper\Method::createGet(),
    'http://my.domain.com',
    ['hello' => 'world']
);

// send the request to get a response
$response = $request->send();

// If we were sending to an API, then we want to json_decode the response
$jsonResponseObject = json_decode($response->getBody());

Switching to a POST/PUT/DELETE is a one line change. E.g.

$request = new Programster\GuzzleWrapper\Request(
    Programster\GuzzleWrapper\Method::createPost(),
    'http://my.domain.com',
    ['hello' => 'world']
);

Testing

Go to the tests folder and run:

php -S localhost:80 RequestDumper.php

Then execute the tests with:

php main.php

This should simply tell you whether each test passed or not.