Use the Rahona API with your PHP scripts in a simplified way with our official library.
To download this library and integrate it inside your PHP script, you can use Composer.
Quick integration with the following command:
composer require rahona/php-rahona
Insert the autoload of composer then this code below.
<?php
/**
* Visit https://panel.rahona-hosting.com
* to get your API key
*/
require __DIR__ . '/vendor/autoload.php';
use Rahona\Api;
$rahona = new Api( $rahona_key,
$rahona_email );
print_r($rahona->get('/me')); // return an array of your personal information
?>
Under the hood, php-rahona
uses GuzzlePHP 6 by default to issue API requests. If everything goes well, it will return the response directly as shown in the examples above. If there is an error like a missing endpoint or object (404), an authentication or authorization error (401 or 403) or a parameter error, the Guzzle will raise a GuzzleHttp\Exception\ClientException
exception. For server-side errors (5xx), it will raise a GuzzleHttp\Exception\ServerException
exception.
You can get the error details with a code like:
<?php
/**
* Visit https://panel.rahona-hosting.com
* to get your API key
*/
require __DIR__ . '/vendor/autoload.php';
use Rahona\Api;
$rahona = new Api($rahona_key, $rahona_email);
try {
$rahona->get('/me');
} catch (GuzzleHttp\Exception\ClientException $e) {
$response = $e->getResponse();
$responseBodyAsString = $response->getBody()->getContents();
echo $responseBodyAsString;
}
?>