| Crates.io | aliexpress-sdk |
| lib.rs | aliexpress-sdk |
| version | 1.0.1 |
| created_at | 2024-09-26 12:04:36.379438+00 |
| updated_at | 2025-03-05 09:08:37.078957+00 |
| description | A Rust implementation of the Aliexpress Open Platform SDK |
| homepage | https://github.com/ThorvaldOF/aliexpress-sdk |
| repository | https://github.com/ThorvaldOF/aliexpress-sdk |
| max_upload_size | |
| id | 1387416 |
| size | 62,551 |
This repository contains a Rust implementation of the Aliexpress SDK. The SDK is designed to handle the complexities of signing requests, managing API parameters, and processing responses. It provides a convenient way to interact with the Aliexpress Open Platform API that require HMAC-SHA256 signing for secure communication.
Add the following to your Cargo.toml to include this SDK in your Rust project:
[dependencies]
aliexpress_sdk = "1.0.0"
Start by creating an IopClient with the server URL, app_key, and app_secret:
use aliexpress_sdk::IopClient;
let client = IopClient::new("https://api.example.com", "your_app_key", "your_app_secret");
Create an IopRequest by specifying the API method you wish to call. You can add parameters and configure the request format:
use aliexpress_sdk::IopRequest;
let mut request = IopRequest::new("getProductDetails", "POST");
request.add_api_param("product_id", "12345");
request.set_format("json");
Execute the request asynchronously using the IopClient:
use tokio::runtime::Runtime;
let runtime = Runtime::new().unwrap();
let response = runtime.block_on(client.execute(&request, None));
match response {
Ok(resp) => println!("Response: {:?}", resp.body()),
Err(err) => eprintln!("Error: {}", err),
}
The SDK returns an IopResponse that contains details of the API response. You can access various fields such as the response code, message, and body:
println!("Code: {:?}", response.code());
println!("Message: {:?}", response.message());
println!("Body: {:?}", response.body());
The SDK includes a function for generating HMAC-SHA256 signatures required by the API:
use aliexpress_sdk::sign;
use std::collections::HashMap;
let secret = "your_secret_key";
let api = "/api/getProductDetails";
let mut parameters = HashMap::new();
parameters.insert("product_id".to_string(), "12345".to_string());
let signature = sign(secret, api, ¶meters);
println!("Generated Signature: {}", signature);
This project is licensed under the MIT License. See the LICENSE file for details.