Installation
To install via npm
use:
npm i spacex-api-wrapper
To install via yarn
use:
yarn add spacex-api-wrapper
Basic Usage
To use the wrapper, require the module and initialise the module:
let SpacexApiWrapper = require("spacex-api-wrapper");
SpacexApiWrapper.info().then(function(data) {
console.log(data);
});
{
"name": "SpaceX",
"founder": "Elon Musk",
"founded": 2002,
"employees": 7000,
"vehicles": 3,
"launch_sites": 3,
"test_sites": 1,
"ceo": "Elon Musk",
"cto": "Elon Musk",
"coo": "Gwynne Shotwell",
"cto_propulsion": "Tom Mueller",
"valuation": 27500000000,
"headquarters": {
"address": "Rocket Road",
"city": "Hawthorne",
"state": "California"
},
"links": {
"website": "https://www.spacex.com/",
"flickr": "https://www.flickr.com/photos/spacex/",
"twitter": "https://twitter.com/SpaceX",
"elon_twitter": "https://twitter.com/elonmusk"
},
"summary": "SpaceX designs, manufactures and launches advanced rockets and spacecraft. The company was founded in 2002 to revolutionize space technology, with the ultimate goal of enabling people to live on other planets."
}
Documentation
This wrapper provides the static methods listed below. Each links to the relevant section of the API's documentation.
Arguments:
id
- Specifies the id of the entity to retrieve.query
- An object listing any additional options or output controls specified in the API's documentation.settings
- Object used to setup axios:method
- Method to use when making requests. Default isget
and is the only method used in the API.baseURL
- The URL of the API.ssl
- Use SSL?version
- Defaults to V3, which this wrapper is designed for. Using other versions may cause the wrapper to stop working or to not cover all endpoints.timeout
- How long before timing out a request.
All arguments other than the id
argument (only required a small number of methods) are optional.
Documentation for the API can be found here.
Capsules
.getAllCapsules(query, settings)
.getCapsule(id, query, settings)
.getUpcomingCapsules(query, settings)
.getPastCapsules(query, settings)
Cores
.getAllCores(query, settings)
.getCore(id, query, settings)
.getUpcomingCores(query, settings)
.getPastCores(query, settings)
Dragons
History
Info
Landing Pads
Launches
.getAllLaunches(query, settings)
.getLaunch()
.getPastLaunches(query, settings)
.getUpcomingLaunches(query, settings)
.getLatestLaunch(query, settings)
.getNextLaunch(query, settings)
Launch Pads
Missions
Payloads
Rockets
Roadster
Ships
FAQs
- What is returned in replace of a 404?
- When the API returns a 404, it occurs usually when an id in an endpoint was not valid. This has been handled in this repository by returning
undefined
.
- When the API returns a 404, it occurs usually when an id in an endpoint was not valid. This has been handled in this repository by returning
- The tests seem a little odd?
- The tests used for this wrapper are copies of r-spacex/SpaceX-API tests. It seems that these are out of date for their own API. Once they are updated and improved I will update the tests here.