A simple SDK for interacting with the Launch Library 2 API.
- PHP >= 7.4
- A LL2 API token (Optional)
Install this library via Composer.
composer require cbzink/launchlibrary
Instantiate an instance of the LL2 class
use cbzink\LaunchLibrary\LL2;
$client = new LL2($apiToken, $apiEndpoint);
Parameter | Required? | Description |
---|---|---|
$apiToken |
No | Provide your own API token for increased rate limits. Default none. |
$apiEndpoint |
No | Provide an alternate API endpoint for switching between prod and dev environments. Default production. |
You can change the pagination limit (default 10
) using setPaginationLimit
.
$client->setPaginationLimit(30);
$client->getPaginationLimit() // (int) 30
Currently available resources include Agencies, Astronauts, Docking Events, Events, Expeditions, Launchers, Launches, Locations, Pads, Space Stations, and Spacecraft.
You can search for resources using the parameters specified in the LL2 API docs.
$results = $client->agencies()->search([
'country_code' => 'US',
]);
Searches are often paginated. An array of resources is available under the results
property, and next()
and previous()
methods are available for moving through pagination.
$agencies = $client->agencies()->search();
// Array of Agency resources.
$resources = $agencies->results;
// Fetch the next page of results
$agencies = $agencies->next();
You can retrieve detailed resources by their ID.
$results = $client->agencies()->fetch(123);
Events and Launches have additional Previous and Upcoming endpoints you can access using the SDK. search()
and fetch()
are available on both.
// Previous
$results = $client->events()->previous()->search();
// Upcoming
$results = $client->launches()->upcoming()->search();
Spacecraft have an additional Flights endpoint you can access using the SDK. search()
and fetch()
are available on both.
$results = $client->spacecraft()->flights()->search();
Inspiration for the design of this SDK was taken from laravel/forge-sdk and KnpLabs/php-github-api.
Launch Library 2 SDK for PHP is open source software licensed under the MIT license.