HttpFull
Extension conversion of 'Httpful' to yii2 extension, (*1)
Installation
The preferred way to install this extension is through composer., (*2)
Since it is not published on packages.org needs to be installed manually using composer
add to your composer.json, (*3)
"repositories":[
{
"type": "git",
"url": "https://path.to/your/repo"
}
]
since the file is local the 'url' should be "url" : "file:///path_to_your_file"
Either run, (*4)
php composer.phar require --prefer-dist segpacto/yii2-httpfull "*"
or add, (*5)
"segpacto/yii2-httpfull": "*"
to the require section of your composer.json
file., (*6)
Usage
Once the extension is installed, simply use it in your code by :, (*7)
// Make a request to the GitHub API with a custom
// header of "X-Trvial-Header: Just as a demo".
$url = "https://api.github.com/users/nategood";
$response = \HttpFull\Request::get($url)
->expectsJson()
->withXTrivialHeader('Just as a demo')
->send();
echo "{$response->body->name} joined GitHub on " .
date('M jS', strtotime($response->body->created_at)) ."\n";
Ex 1:
Send off a GET request. Get automatically parsed JSON response.
The library notices the JSON Content-Type in the response and automatically parses the response into a native PHP object., (*8)
$uri = "https://www.googleapis.com/freebase/v1/mqlread?query=%7B%22type%22:%22/music/artist%22%2C%22name%22:%22The%20Dead%20Weather%22%2C%22album%22:%5B%5D%7D";
$response = \HttpFull\Request::get($uri)->send();
echo 'The Dead Weather has ' . count($response->body->result->album) . " albums.\n";
Ex 2:, (*9)
$uri = 'https://example.net/person.xml';
$response = \HttpFull\Request::get($uri)
->expectsXml()
->send();
echo "Name: $response->body->name";
Note : This is based on the package
shared by nategood. This is only
a conversion to use as Yii2 extension.
For further explanation and documentation of the package go directly their documentation., (*10)