Skip to content

Use the Rahona API with your PHP scripts in a simplified way with our official library.

Notifications You must be signed in to change notification settings

Rahona-Hosting/php-rahona

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Client for Rahona API

Use the Rahona API with your PHP scripts in a simplified way with our official library.

Discord Chat Downloads License

Quickstart

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

How to use Rahona API

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
?>

How to print API error details?

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;
}
?>

About

Use the Rahona API with your PHP scripts in a simplified way with our official library.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages