Skip to content

Official PHP SDK for the FortisX API. Composer package providing a clean and modern interface for all REST endpoints.

License

Notifications You must be signed in to change notification settings

fortisx/php-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FortisX PHP SDK

This guide explains how to interact with the API using the PHP client.


Installation

composer require fortisx/sdk

Initialization

require 'vendor/autoload.php';

use FortisX\SDK\API;

$api = new API('YOUR_API_KEY');

Constructor options

Name Type Default Description
$apiKey string API key used for authorization
$baseUrl string https://api.fortisx.fi/v1 Override if using a custom environment
$timeout int 10 Request timeout in seconds

Methods

Method Arguments Returns Description
get(string $endpoint, array $params = []) endpoint path, optional params array Performs a GET request
post(string $endpoint, array $data = []) endpoint path, optional data array Performs a POST request
put(string $endpoint, array $data = []) endpoint path, optional data array Performs a PUT request
delete(string $endpoint) endpoint path array Performs a DELETE request

All requests use GuzzleHttp\Client and automatically include the following headers:

[
  'Authorization' => "Bearer {$apiKey}",
  'Accept' => 'application/json'
]

Error Handling

When a network or server error occurs, an exception of type APIError is thrown.

namespace FortisX\SDK;

class APIError extends \Exception {
    public int $status;
    public array $details;

    public function __construct(string $message, int $status = 0, array $details = []) {
        parent::__construct($message);
        $this->status = $status;
        $this->details = $details;
    }
}
Field Type Description
$message string Short description of the error
$status int HTTP status code
$details array Full response body if available

Example:

use FortisX\SDK\API;
use FortisX\SDK\APIError;

$api = new API('demo-key');

try {
    $res = $api->get('ping');
    print_r($res);
} catch (APIError $err) {
    echo "API error [{$err->status}]: {$err->getMessage()}";
} catch (Exception $e) {
    echo "Unexpected error: {$e->getMessage()}";
}

Example: /ping Endpoint

require 'vendor/autoload.php';

use FortisX\SDK\API;

$api = new API('demo-key');
$response = $api->get('ping');

print_r($response); // ['status' => 'ok']

About

Official PHP SDK for the FortisX API. Composer package providing a clean and modern interface for all REST endpoints.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages