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.
composer require rokde/http-client
You have two options
- Use the helper function
http()
- 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.
// 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');
$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.
Run the tests with:
composer test