Bicycle HTTP client
Yet another PSR HTTP messages client, with bicycle name, jep.
composer require evilfreelancer/bicycle
How to use
Bicycle client support any correct query methods to server (eg GET, POST, etc).
Basic example
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Bicycle\Uri;
use Bicycle\Request;
$uri = new \Bicycle\Uri('https://api.haipit.news/api/v1/news/random');
$client = new \Bicycle\Client();
// Make query
$message = $client
->setMethod('get')
->setUri($uri)
->request();
// Content of body in RAW format
echo $message->getRawBody() . "\n";
How to convert JSON to array
You can extract ready for usage JSON from $response
variable (by
default raw html inside), for this you just need call getJsonBody
method:
// Convert JSON into array
$output = $message->getJsonBody();
And voila the array inside $output
variable.
print_r($output);
About authorization
You can use Client->setAuth($user, $pass)
method if you need make query with
basic HTTP autorization.
About Bearer OAuth2 tokens
You can set any OAuth2 tokect in your query via Client->setBearer($token)
method.