Skip to content

Commit

Permalink
docs(example): update rds example
Browse files Browse the repository at this point in the history
  • Loading branch information
r4ntix committed Jul 15, 2023
1 parent ec65ef6 commit 8a06097
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions examples/rds.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
use aliyun_openapi_core_rust_sdk::client::rpc::RPClient;
use std::env;
use std::error::Error;
use std::{collections::HashMap, env};

use aliyun_openapi_core_rust_sdk::client::rpc::RPClient;
use serde::{Deserialize, Serialize};
use serde_json::Value;

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
struct Region {
region_id: String,
region_endpoint: String,
zone_id: String,
zone_name: String,
local_name: String,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
struct RegionList {
request_id: String,
regions: HashMap<String, Vec<Region>>,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
struct DBInstances {
items: HashMap<String, Vec<Value>>,
next_token: String,
page_number: usize,
page_record_count: usize,
request_id: String,
total_record_count: usize,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
Expand All @@ -11,23 +42,23 @@ async fn main() -> Result<(), Box<dyn Error>> {
"https://rds.aliyuncs.com/",
);

// call `DescribeRegions` with empty queries.
// call `DescribeRegions` with empty queries and return `RegionList`
let response = aliyun_openapi_client
.clone()
.version("2014-08-15")
.get("DescribeRegions")
.text()
.json::<RegionList>()
.await?;
println!("DescribeRegions response:\n{response}\n");
println!("DescribeRegions response: {response:#?}");

// call `DescribeDBInstances` with queries.
// call `DescribeDBInstances` with queries and return `DBInstances`
let response = aliyun_openapi_client
.version("2014-08-15")
.get("DescribeDBInstances")
.query([("RegionId", "cn-hangzhou")])
.text()
.json::<DBInstances>()
.await?;
println!("DescribeDBInstances response:\n{response}");
println!("DescribeDBInstances response: {response:#?}");

Ok(())
}

0 comments on commit 8a06097

Please sign in to comment.