Crates.io | reqsign |
lib.rs | reqsign |
version | 0.16.1 |
source | src |
created_at | 2022-03-12 08:40:25.881148 |
updated_at | 2024-11-04 08:05:10.646807 |
description | Signing API requests without effort. |
homepage | |
repository | https://github.com/Xuanwo/reqsign |
max_upload_size | |
id | 548683 |
size | 352,555 |
Signing API requests without effort.
Most API is simple. But they could be complicated when they are hidden from complex abstraction. reqsign
bring the simple API back: build, sign, send.
use anyhow::Result;
use reqsign::AwsConfig;
use reqsign::AwsLoader;
use reqsign::AwsV4Signer;
use reqwest::Client;
use reqwest::Request;
use reqwest::Url;
#[tokio::main]
async fn main() -> Result<()> {
// Signer can load region and credentials from environment by default.
let client = Client::new();
let config = AwsConfig::default().from_profile().from_env();
let loader = AwsLoader::new(client.clone(), config);
let signer = AwsV4Signer::new("s3", "us-east-1");
// Construct request
let url = Url::parse("https://s3.amazonaws.com/testbucket")?;
let mut req = reqwest::Request::new(http::Method::GET, url);
// Signing request with Signer
let credential = loader.load().await?.unwrap();
signer.sign(&mut req, &credential)?;
// Sending already signed request.
let resp = client.execute(req).await?;
println!("resp got status: {}", resp.status());
Ok(())
}
reqsign::AliyunOssSigner
reqsign::AwsV4Signer
reqsign::AzureStorageSigner
reqsign::GoogleSigner
reqsign::HuaweicloudObsSigner
Check out the CONTRIBUTING.md guide for more details on getting started with contributing to this project.
Submit issues for bug report or asking questions in discussion.
Inspired a lot from: