Crates.io | qiniu-apis |
lib.rs | qiniu-apis |
version | 0.2.4 |
source | src |
created_at | 2022-04-07 06:57:30.795411 |
updated_at | 2023-12-26 07:56:07.955087 |
description | Qiniu HTTP APIs for Rust |
homepage | https://www.qiniu.com |
repository | https://github.com/qiniu/rust-sdk.git |
max_upload_size | |
id | 563510 |
size | 706,397 |
这是一个基于 qiniu-apis-specs
自动生成的 Rust 库,基于 qiniu-http-client
,用于调用七牛 HTTP API。
该库同时提供阻塞客户端和异步客户端,异步客户端则需要启用 async
功能。
该库致力于根据 qiniu-apis-specs
提供的 YAML 描述文件,在不理解业务逻辑的前提下,提供简单的封装方法方便用户正确调用 API。
该库可以通过启用不同的功能来选择不同的 HTTP 客户端实现,
例如可以通过启用 ureq
功能导入 qiniu-ureq
库作为 HTTP 客户端,
通过启用 reqwest
功能导入 qiniu-reqwest
库作为 HTTP 客户端,
通过启用 isahc
功能导入 qiniu-isahc
库作为 HTTP 客户端。
您也可以显式传入任何基于 qiniu-http
接口的 HTTP 客户端实现来提供给 qiniu-apis
使用。
ureq
[dependencies]
qiniu-apis = { version = "0.2.1", features = ["ureq"] }
[dependencies]
qiniu-apis = { version = "0.2.1", features = ["async", "isahc"] }
[dependencies]
qiniu-apis = { version = "0.2.1", features = ["async", "reqwest"] }
c_ares
启用 c-ares
库作为 DNS 解析器
trust_dns
启用 trust-dns
库作为 DNS 解析器
dns-over-https
启用 trust-dns
库作为 DNS 解析器,并使用 DOH 协议
dns-over-tls
启用 trust-dns
库作为 DNS 解析器,并使用 DOT 协议
use qiniu_apis::{
credential::Credential,
http_client::{AllRegionsProvider, RegionsProvider, RegionsProviderEndpoints},
storage::create_bucket::PathParams,
Client,
};
let credential = Credential::new("abcdefghklmnopq", "1234567890");
let region = AllRegionsProvider::new(credential.to_owned())
.get(Default::default())?;
Client::default()
.storage()
.create_bucket()
.new_request(
RegionsProviderEndpoints::new(®ion),
PathParams::default()
.set_bucket_as_str("new-bucket-name")
.set_region_as_str("z1"),
credential,
)
.call()?;
use qiniu_apis::{
credential::Credential,
http_client::{BucketRegionsQueryer, RegionsProviderEndpoints},
storage::set_bucket_taggings::{QueryParams, RequestBody, TagInfo, Tags},
Client,
};
let credential = Credential::new("abcdefghklmnopq", "1234567890");
let bucket_name = "test-bucket";
let region = BucketRegionsQueryer::new().query(credential.access_key().to_owned(), bucket_name);
let mut tag1 = TagInfo::default();
tag1.set_key_as_str("tag_key1".to_owned());
tag1.set_value_as_str("tag_val1".to_owned());
let mut tag2 = TagInfo::default();
tag2.set_key_as_str("tag_key2".to_owned());
tag2.set_value_as_str("tag_val2".to_owned());
let mut tags = Tags::default();
tags.push_tag_info(tag1);
tags.push_tag_info(tag2);
let mut req_body = RequestBody::default();
req_body.set_tags(tags);
Client::default()
.storage()
.set_bucket_taggings()
.new_request(RegionsProviderEndpoints::new(®ion), credential)
.query_pairs(QueryParams::default().set_bucket_as_str(bucket_name))
.call(&req_body)?;
use qiniu_apis::{
credential::Credential,
http_client::{BucketRegionsQueryer, RegionsProviderEndpoints},
storage::get_bucket_taggings::QueryParams,
Client,
};
let credential = Credential::new("abcdefghklmnopq", "1234567890");
let bucket_name = "test-bucket";
let region = BucketRegionsQueryer::new().query(credential.access_key().to_owned(), bucket_name);
let tags = Client::default()
.storage()
.get_bucket_taggings()
.new_request(RegionsProviderEndpoints::new(®ion), credential)
.query_pairs(QueryParams::default().set_bucket_name_as_str(bucket_name))
.call()?
.into_body()
.get_tags()
.to_tag_info_vec();
for tag in tags {
println!("{}: {}", tag.get_key_as_str(), tag.get_value_as_str());
}
use qiniu_apis::{
credential::Credential,
http_client::{AllRegionsProvider, RegionsProvider, RegionsProviderEndpoints},
storage::create_bucket::PathParams,
Client,
};
let credential = Credential::new("abcdefghklmnopq", "1234567890");
let region = AllRegionsProvider::new(credential.to_owned())
.async_get(Default::default())
.await?;
Client::default()
.storage()
.create_bucket()
.new_async_request(
RegionsProviderEndpoints::new(®ion),
PathParams::default()
.set_bucket_as_str("new-bucket-name")
.set_region_as_str("z1"),
credential,
)
.call()
.await?;
use qiniu_apis::{
credential::Credential,
http_client::{BucketRegionsQueryer, RegionsProviderEndpoints},
storage::set_bucket_taggings::{QueryParams, RequestBody, TagInfo, Tags},
Client,
};
let credential = Credential::new("abcdefghklmnopq", "1234567890");
let bucket_name = "test-bucket";
let region = BucketRegionsQueryer::new().query(credential.access_key().to_owned(), bucket_name);
let mut tag1 = TagInfo::default();
tag1.set_key_as_str("tag_key1".to_owned());
tag1.set_value_as_str("tag_val1".to_owned());
let mut tag2 = TagInfo::default();
tag2.set_key_as_str("tag_key2".to_owned());
tag2.set_value_as_str("tag_val2".to_owned());
let mut tags = Tags::default();
tags.push_tag_info(tag1);
tags.push_tag_info(tag2);
let mut req_body = RequestBody::default();
req_body.set_tags(tags);
Client::default()
.storage()
.set_bucket_taggings()
.new_async_request(RegionsProviderEndpoints::new(®ion), credential)
.query_pairs(QueryParams::default().set_bucket_as_str(bucket_name))
.call(&req_body)
.await?;
use qiniu_apis::{
credential::Credential,
http_client::{BucketRegionsQueryer, RegionsProviderEndpoints},
storage::get_bucket_taggings::QueryParams,
Client,
};
let credential = Credential::new("abcdefghklmnopq", "1234567890");
let bucket_name = "test-bucket";
let region = BucketRegionsQueryer::new().query(credential.access_key().to_owned(), bucket_name);
let tags = Client::default()
.storage()
.get_bucket_taggings()
.new_async_request(RegionsProviderEndpoints::new(®ion), credential)
.query_pairs(QueryParams::default().set_bucket_name_as_str(bucket_name))
.call()
.await?
.into_body()
.get_tags()
.to_tag_info_vec();
for tag in tags {
println!("{}: {}", tag.get_key_as_str(), tag.get_value_as_str());
}
1.70.0
This project is licensed under the MIT license.