fastly/fastly

A PHP client library for interacting with most facets of the Fastly API.

v6.0.0 2024-12-06 06:59 UTC

README

A PHP client library for interacting with most facets of the Fastly API.

Installation

Requires PHP 7.3 or later.

To install via Composer, add the following to your project's composer.json:

{
  "require": {
    "fastly/fastly": "*@dev"
  }
}

Then run composer install.

Composer generates a vendor/autoload.php file. You can include this file and start using the classes provided by this client without any extra work:

<?php
require_once('/path/to/project/vendor/autoload.php');

Usage

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Authorize the client with a Fastly API token.
$config = Fastly\Configuration::getDefaultConfiguration()->setApiToken('YOUR_API_TOKEN');

// Alternatively, set the FASTLY_API_TOKEN environment variable:
// $config = Fastly\Configuration::getDefaultConfiguration();

$apiInstance = new Fastly\Api\(
    // Optionally, pass a custom client that implements `GuzzleHttp\ClientInterface`.
    // `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client(),
    $config
);

$options['service_id'] = 'SU1Z0isxPaozGVKXdv0eY'; // string
$options['version_id'] = 56; // int
$options['name'] = 'my_acl'; // string

try {
    $result = $apiInstance->createAcl($options);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling AclApi->createAcl: ', $e->getMessage(), PHP_EOL;
}

Authorization

Note

The Fastly API requires an API token for most operations.

Set up the API token in the PHP client by using the setApiToken method of a configuration as shown:

Fastly\Configuration::getDefaultConfiguration()->setApiToken('YOUR_API_TOKEN');

Alternatively, set the FASTLY_API_TOKEN environment variable instead of using setApiToken.

Fastly\Configuration::getDefaultConfiguration();

API Endpoints

The main documentation for the Fastly API can be found on our Developer Hub.

Table of API endpoints

Issues

The fastly-php API client currently does not support the following endpoints:

If you encounter any non-security-related bug or unexpected behavior, please file an issue using the bug report template.

Security issues

Please see our SECURITY.md for guidance on reporting security-related issues.

License

MIT.