rokde/http-client

This package is abandoned and no longer maintained. No replacement package was suggested.

A http client library without any dependencies. Just vanilla php.

1.1.0 2019-03-14 16:18 UTC

This package is auto-updated.

Last update: 2024-01-15 03:34:15 UTC


README

Latest Stable Version Latest Unstable Version License Total Downloads

This http client library does not have any dependencies like curl or guzzle. It uses plain php functions to handle the most common http requests.

Installation

composer require rokde/http-client

Usage

You have two options

  1. Use the helper function http()
  2. Use the full-blown class stack provided by the package

I recommend the use of the http() function to keep the packages purpose in mind: simplicity.

Using http()

// GET (get from uri)
/** @var string $response */
$response = http('https://httpbin.org/get');

// POST (post data to uri)
/** @var \Rokde\HttpClient\Response $response */
$response = http()->post(['data' => 'value'], 'https://httpbin.org/post');

Using the class version

$client = new \Rokde\HttpClient\Client();

$request = new \Rokde\HttpClient\Request('https://httpbin.org/get', 'GET', [
  'accept' => 'application/json',
  'x-verify-test' => 'true',
]);

$response = $client->send($request);

if ($response->isOk()) {
  $resultString = $response->content();
}

Further usage examples can be found at the /tests folder of this package.

Testing

Run the tests with:

composer test