aliyun_openapi_core_rust_sdk/lib.rs
1//! Aliyun OpenAPI POP core SDK for Rust.
2//!
3//! ## Notes
4//!
5//! You must know your `AK`(`accessKeyId/accessKeySecret`), and the aliyun product's `endpoint` and `apiVersion`.
6//!
7//! For example, The [ECS OpenAPI](https://help.aliyun.com/document_detail/25490.html), the API version is `2014-05-26`.
8//!
9//! And the endpoint list can be found at [here](https://help.aliyun.com/document_detail/25489.html), the center endpoint is ecs.aliyuncs.com. Add http protocol `http` or `https`, should be `https://ecs.aliyuncs.com/`.
10//!
11//! ## Install
12//!
13//! Run the following Cargo command in your project directory:
14//!
15//! ```shell
16//! cargo add aliyun-openapi-core-rust-sdk
17//! ```
18//!
19//! Or add the following line to your Cargo.toml:
20//!
21//! ```toml
22//! aliyun-openapi-core-rust-sdk = "1.0.0"
23//! ```
24//!
25//! ## Usage
26//!
27//! The RPC style client:
28//!
29//! ```rust
30//! use std::collections::HashMap;
31//! use std::env;
32//! use std::error::Error;
33//!
34//! use aliyun_openapi_core_rust_sdk::client::rpc::RPClient;
35//! use serde::{Deserialize, Serialize};
36//!
37//! #[derive(Serialize, Deserialize, Debug)]
38//! #[serde(rename_all = "PascalCase")]
39//! struct Region {
40//! region_id: String,
41//! region_endpoint: String,
42//! local_name: String,
43//! }
44//!
45//! #[derive(Serialize, Deserialize, Debug)]
46//! #[serde(rename_all = "PascalCase")]
47//! struct RegionList {
48//! request_id: String,
49//! regions: HashMap<String, Vec<Region>>,
50//! }
51//!
52//! #[tokio::main]
53//! async fn main() -> Result<(), Box<dyn Error>> {
54//! // create rpc style api client.
55//! let aliyun_openapi_client = RPClient::new(
56//! env::var("ACCESS_KEY_ID")?,
57//! env::var("ACCESS_KEY_SECRET")?,
58//! "https://ecs.aliyuncs.com/",
59//! );
60//!
61//! // call `DescribeRegions` with empty queries, return `RegionList`
62//! let response = aliyun_openapi_client
63//! .clone()
64//! .version("2014-05-26")
65//! .get("DescribeRegions")
66//! .json::<RegionList>()
67//! .await?;
68//! println!("DescribeRegions response: {response:#?}");
69//!
70//! // call `DescribeInstances` with queries, return `String`
71//! let response = aliyun_openapi_client
72//! .version("2014-05-26")
73//! .get("DescribeInstances")
74//! .query([("RegionId", "cn-hangzhou")])
75//! .text()
76//! .await?;
77//! println!("DescribeInstances response: {response}");
78//!
79//! Ok(())
80//! }
81//! ```
82//!
83//! The ROA style client:
84//!
85//! ```rust
86//! use std::collections::HashMap;
87//! use std::env;
88//! use std::error::Error;
89//!
90//! use aliyun_openapi_core_rust_sdk::client::roa::ROAClient;
91//! use serde::{Deserialize, Serialize};
92//! use serde_json::json;
93//!
94//! #[derive(Serialize, Deserialize, Debug)]
95//! #[serde(rename_all = "PascalCase")]
96//! struct TranslateData {
97//! word_count: String,
98//! translated: String,
99//! }
100//!
101//! #[derive(Serialize, Deserialize, Debug)]
102//! #[serde(rename_all = "PascalCase")]
103//! struct Translate {
104//! request_id: String,
105//! data: TranslateData,
106//! code: String,
107//! }
108//!
109//! #[tokio::main]
110//! async fn main() -> Result<(), Box<dyn Error>> {
111//! // create roa style api client.
112//! let aliyun_openapi_client = ROAClient::new(
113//! env::var("ACCESS_KEY_ID")?,
114//! env::var("ACCESS_KEY_SECRET")?,
115//! "http://mt.aliyuncs.com",
116//! );
117//!
118//! // create params.
119//! let mut params = HashMap::new();
120//! params.insert("SourceText", "你好");
121//! params.insert("SourceLanguage", "zh");
122//! params.insert("TargetLanguage", "en");
123//! params.insert("FormatType", "text");
124//! params.insert("Scene", "general");
125//!
126//! // call `Translate` with json params, return `Translate`
127//! let response = aliyun_openapi_client
128//! .version("2018-04-08")
129//! .post("/api/translate/web/general")
130//! .header([("Content-Type".to_string(), "application/json".to_string())])?
131//! .body(json!(params).to_string())?
132//! .json::<Translate>()
133//! .await?;
134//!
135//! println!("Translate response: {response:#?}");
136//!
137//! Ok(())
138//! }
139//! ```
140//!
141//! ## Examples
142//!
143//! Export AK info to env, then run `cargo run --example <NAME>`:
144//!
145//! ```sh
146//! export ACCESS_KEY_ID=<access_key_id>
147//! export ACCESS_KEY_SECRET=<access_key_secret>
148//!
149//! # ecs example
150//! cargo run --example ecs
151//!
152//! # rds example
153//! cargo run --example rds
154//!
155//! # slb example
156//! cargo run --example slb
157//!
158//! # vpc example
159//! cargo run --example vpc
160//!
161//! # log service(SLS) example
162//! cargo run --example log_service
163//! ```
164#![allow(deprecated)]
165
166mod roa;
167mod rpc;
168
169#[deprecated(
170 since = "1.0.0",
171 note = "Please use the `aliyun_openapi_core_rust_sdk::client::roa::ROAClient` instead"
172)]
173pub use crate::roa::Client as ROAClient;
174
175#[deprecated(
176 since = "1.0.0",
177 note = "Please use the `aliyun_openapi_core_rust_sdk::client::rpc::RPClient` instead"
178)]
179pub use crate::rpc::Client as RPClient;
180
181pub mod client;