fortnite-api/php-wrapper

This package is abandoned and no longer maintained. No replacement package was suggested.

PHP wrapper for https://fortnite-api.com

v1.0.0 2019-12-18 08:36 UTC

This package is not auto-updated.

Last update: 2024-04-18 04:36:27 UTC


README

GitHub release (latest by date) Packagist GitHub issues MIT License

PHP version Guzzle HTTP Donate Discord

This library offers a complete wrapper around the endpoints of fortnite-api.com.

All classes and JSON objects are well documented and support autocompletion and type hints for each object and property.

We also have async requests for each endpoint!

Composer

composer require fortnite-api/php-wrapper

Documentation

Here is a quick overview of the API so you can get started very quickly.

If you need an in-use example then please take a look at the index.php in my test folder where i use some of the endpoints.

  • General usage
use FortniteApi\FortniteApi;

require_once __DIR__ . '/../vendor/autoload.php';

$api = new FortniteApi();
  • FortniteApi class
$api = new FortniteApi();

// accesses the cosmetics endpoint (https://fortnite-api.com/cosmetics)
$api->cosmetics->...

// accesses the news endpoint (https://fortnite-api.com/news)
$api->news->...

// accesses the shop endpoint (https://fortnite-api.com/shop)
$api->shop->...

// accesses the creatorcode endpoint (https://fortnite-api.com/creatorcode)
$api->creatorCode->...
// returns the base uri of the api (https://fortnite-api.com)
FortniteApi::getBaseUri();

// returns an array of all supported languages
FortniteApi::getSupportedLanguages();
  • FortniteApiError
$result = $api->cosmetics->getAll();

if ($result === null)
{
    $lastError = FortniteApiError::getLastError();

    // this just shows which members you can access
    $members = [
        $lastError->statusCode,
        $lastError->reasonPhrase,
        $lastError->body,
        $lastError->message
    ];
}
// Returns the error set by the last request or false if none is set.
FortniteApiError::getLastError();

// Determines whether an error occured within the last called function.
FortniteApiError::hasLastError();
  • Async methods

Each method in an endpoint has an equivalent async method (i.e. getAsync) which returns an awaitable task. You can await the response at any point in your script.

// returns "instantly"
$task = $api->cosmetics->getAllAsync();
// retreives the result (the one you get from non-async versions)
$result = $task->await();
  • Endpoints

Each method in one of the endpoints return null on failure. Autocompletion and type hints are provided on each object.

Objects are mapped with the exact same layout as on fortnite-api.com/documentation but without their status and data properties which already get validated for you.

If you need more information about properties and methods then please take a look at the actual implementation.

Endpoints

JSON Objects

  • The query parameter

Some methods require a $query parameter to work. You can find possible query parameters within the official documentation. An example for such an query array would be:

// key value pairs also support arrays as value if the api allows this
$query = [
    "rarity" => "uncommon",
    "hasIcon" => true
];

Contribute

if you can provide any help, may it only be spell checking please contribute!

We are open for any contribution.

License

API developed by Fortnite-API.com