Calling the API
Now that the project has been set up, we can use the vasystem-api
crate to call the API.
In this example, we will use the same example values as in the Authentication
guide.
Please note that we recommend not hard-coding the values in your code, but instead using environment variables or a configuration file. We have hard-coded them in the example below for simplicity.
src/main.rs
use vasystem_api::{
api::{ListAirlinesRequest, ListRoutesRequest},
Client, Request,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::connect(
"staralliancevirtual.org",
"client-id",
"client-secret",
vec!["airlines".to_string(), "routes".to_string()],
)
.await?;
let response = client
.airlines()
.list_airlines(Request::new(ListAirlinesRequest {}))
.await?;
println!("RESPONSE = {:?}", response);
Ok(())
}
Replace the values in the Client::connect
call with the values you
received from the Authentication guide.
You can now run the code with cargo run
and you should see the following output:
RESPONSE = Response { metadata: MetadataMap { headers: {"content-type": "application/grpc", "grpc-status": "0", "grpc-message": ""} }, message: ListAirlinesResponse { airlines: [Airline { id: "...", icao_code: "...", iata_code: "..", display_icao_code: "...", display_iata_code: "..", name: "..." }, ...] }, extensions: Extensions }