space-rx

Crates.io Documentation

Rust wrapper over the unofficial SpaceX API (which can be found here).

Documentation

Installation

Add this to your Cargo.toml file:

toml [dependencies] space_rx = "0.2"

Overview

This crate provides easy to use request builders for all available endpoints in the unofficial SpaceX API. These request builders return a model after being sent, which in turn gives you type-safe, Rustacious access to all fields exposed by each of the endpoints.

Examples

Here's an example in which we make a request to the v2/rockets/{rocket_id} endpoint - we specify the rocket_id as a field in the request builder.

```rust extern crate space_rx;

use spacerx::v2api::requests::rocket::*;

fn main() { let req = RocketRequestBuilder::default().rocketid("falcon9").build().unwrap(); let rocket = spacerx::send(&req).unwrap();

println!("The Falcon 9 weighs {:?}lbs.  Wow!", rocket.mass.lb);
println!("The Falcon 9's landing legs are made out of {:?}.", rocket.landing_legs.material.unwrap());
println!("The Falcon 9's {:?} engine(s) use {:?} and {:?} as propellant.", rocket.engines.number, rocket.engines.propellant_1, rocket.engines.propellant_2);

} ```

How's Starman doing? Let's find out!

```rust extern crate space_rx;

use spacerx::v2api::requests::info::*;

fn main() { let req = RoadsterInfoRequestBuilder::default().build().unwrap(); let roadsterinfo = spacerx::send(&req).unwrap();

println!("Here's how Starman is doing: {:?}", roadster_info);

} ```

The launch style endpoints have lots of potential parameters to filter requests. Let's try some of those. ```rust extern crate space_rx;

use spacerx::SortDir; use spacerx::v2_api::requests::launch::*;

fn main() { let req = AllLaunchesRequestBuilder::default().reused(true) .start("2010-06-22") .customer("Telkom") .site_name("CCAFS SLC 40") .order(SortDir::DESC) .build() .unwrap();

let launches = space_rx::send(&req).unwrap();

println!("{:?}", launches);

} ```

And here we get some information about the Dragon 1 capsule.

```rust extern crate space_rx;

use spacerx::v2api::requests::capsule::*;

fn main() { let req = CapsuleRequestBuilder::default().capsuleid("dragon1").build().unwrap(); let capsule = spacerx::send(&req).unwrap();

println!("The Dragon 1 capsule can hold {:?} people.", capsule.crew_capacity);
println!("How much junk does the Dragon 1 capsule have in the trunk?  Well, this much: {:?}.", capsule.trunk);

} ```

Curious to know what launchpads SpaceX uses? Let's try that.

```rust extern crate space_rx;

use spacerx::v2api::requests::launchpad::*;

fn main() { let req = LaunchpadRequestBuilder::default().launchpadid("ksclc39a").build().unwrap(); let kennedyspacecenter39alaunchpad = spacerx::send(&req).unwrap();

println!("{:?} has launched these rockets: {:?}.", kennedy_space_center_39a_launchpad.full_name, kennedy_space_center_39a_launchpad.vehicles_launched);
println!("{:?} is located at {:?}.", kennedy_space_center_39a_launchpad.full_name, kennedy_space_center_39a_launchpad.location);

} ```

How about the parts used in all capsules? We can find that, too.

```rust extern crate space_rx;

use spacerx::v2api::requests::part::*;

fn main() { let req = AllCapsulePartsRequestBuilder::default().build().unwrap(); let capsuleparts = spacerx::send(&req).unwrap();

println!("Here are the parts used in SpaceX capsules: {:?}", capsule_parts);

} ```

License

This is under Apache/2 or MIT license, per your choice. All contributions are also given under the same license.