| Crates.io | openapi-sdk |
| lib.rs | openapi-sdk |
| version | 0.1.1 |
| created_at | 2025-10-01 08:22:34.139721+00 |
| updated_at | 2025-10-01 08:41:44.3967+00 |
| description | A fully-featured and blazing-fast Rust API client to interact with OpenapiĀ® |
| homepage | https://openapi.com/ |
| repository | https://github.com/openapi/openapi-rust-sdk |
| max_upload_size | |
| id | 1862268 |
| size | 160,415 |
This client is used to interact with the API found at openapi.it
Before using the OpenApi IT Rust Client, you will need an account at openapi.it and an API key to the sandbox and/or production environment
You can add the OpenApi IT Rust Client to your project with the following command:
cargo add openapi-sdk
The client has two main operational modes:
Use the OauthClient to generate access tokens for API access:
use openapi_client::OauthClient;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
struct TokenResponse {
token: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the OAuth client
let oauth_client = OauthClient::new("<your_username>", "<your_apikey>", true)?;
// Create a token for a list of scopes
let scopes = vec![
"GET:test.imprese.openapi.it/advance",
"POST:test.postontarget.com/fields/country",
];
let ttl = 3600;
let result = oauth_client.create_token(scopes, ttl).await?;
// The string response can be parsed into a custom object
let resp: TokenResponse = serde_json::from_str(&result)?;
println!("Generated token: {}", resp.token);
// Delete the token when done
let _result = oauth_client.delete_token(resp.token).await?;
Ok(())
}
Use the Client to make API calls with your access tokens:
use openapi_client::Client;
use serde::Serialize;
use std::collections::HashMap;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the client with your access token
let client = Client::new("<your_access_token>".to_string())?;
// Make a request with parameters
let mut params = HashMap::new();
params.insert("denominazione", "altravia");
params.insert("provincia", "RM");
params.insert("codice_ateco", "6201");
let result = client
.request::<serde_json::Value>(
"GET",
"https://test.imprese.openapi.it/advance",
None,
Some(params),
)
.await?;
println!("API Response: {}", result);
// Make a request with a JSON payload
#[derive(Serialize)]
struct Query {
country_code: String,
}
#[derive(Serialize)]
struct Payload {
limit: u64,
query: Query,
}
let query = Query {
country_code: "IT".to_string(),
};
let payload = Payload { limit: 10, query };
let result = client
.request(
"POST",
"https://test.postontarget.com/fields/country",
Some(&payload),
None,
)
.await?;
println!("POST Response: {}", result);
Ok(())
}
You can find complete examples in the examples/ directory:
examples/token_generation.rs - Token generation exampleexamples/api_calls.rs - API calls exampleRun examples with:
cargo run --example token_generation
cargo run --example api_calls
Run tests with:
cargo test
Contributions are always welcome!
See contributing.md for ways to get started.
Please adhere to this project's code of conduct.