mawuekom/http-request-wrapper

A simple and lighter wrapper around Guzzle HTTP client

1.4.1 2021-06-19 09:54 UTC

This package is auto-updated.

Last update: 2024-12-19 17:52:00 UTC


README

License

This package provide a simple and lighter wrapper around Guzzle HTTP client

Installation

You can install the package via composer:

composer require mawuekom/http-request-wrapper

Usage

// Simple usage

use Mawuekom\HttpRequestWrapper\HttpRequest;

$request = new HttpRequest('http://httpbin.org');
$response = $request ->send('GET', 'get');

echo $response ->getBody();

Using custom methods

// Simple usage

use Mawuekom\HttpRequestWrapper\HttpRequest;

$request = new HttpRequest('http://httpbin.org');
$response = $request ->get('get');

// You can also override default base URI
$response = $request ->get('http://httpbin.org/get');

$request ->post('http://httpbin.org/post');
$request ->put('http://httpbin.org/put');
$request ->patch('http://httpbin.org/patch');
$request ->delete('http://httpbin.org/delete');

You can also use helper

use Mawuekom\HttpRequestWrapper\Helpers\HttpRequestHelper;

class Test
{
    use HttpRequestHelper;

    private $baseUri = 'http://httpbin.org/';

    public function data()
    {
        $res = $this ->makeRequest('GET', 'get');

        return $res ->getBody();
    }

    public function getData()
    {
        $res = $this ->get('get');

        return $res ->getBody();
    }
}

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.