Skip to content

Commit

Permalink
docs(example): update vpc example
Browse files Browse the repository at this point in the history
  • Loading branch information
r4ntix committed Jul 9, 2023
1 parent 191af8e commit 7e0ba9c
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions examples/vpc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
use aliyun_openapi_core_rust_sdk::client::rpc::RPClient;
use std::collections::HashMap;
use std::env;
use std::error::Error;

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,
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 VpcList {
request_id: String,
total_count: usize,
vpcs: HashMap<String, Vec<Value>>,
page_size: usize,
page_number: usize,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// create rpc style api client.
Expand All @@ -11,23 +40,23 @@ async fn main() -> Result<(), Box<dyn Error>> {
"https://vpc.aliyuncs.com/",
);

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

// call `DescribeVpcs` with queries.
// call `DescribeVpcs` with queries, return `VpcList`
let response = aliyun_openapi_client
.version("2016-04-28")
.get("DescribeVpcs")
.query([("RegionId", "cn-hangzhou")])
.text()
.json::<VpcList>()
.await?;
println!("DescribeVpcs response:\n{response}");
println!("DescribeVpcs response: {response:#?}");

Ok(())
}

0 comments on commit 7e0ba9c

Please sign in to comment.