Cargo.toml
toml
[dependencies]
reqwest = { version = "0.12", features = ["json", "multipart"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
Rust Example
rust
use reqwest::Client;
use serde::Deserialize;
#[derive(Deserialize)]
struct UploadResponse { job: String }
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let api_key = "ocr_your_api_key";
// Upload
let pdf = tokio::fs::read("invoice.pdf").await?;
let form = reqwest::multipart::Form::new()
.part("file", reqwest::multipart::Part::bytes(pdf)
.file_name("invoice.pdf"));
let upload: UploadResponse = client
.post("https://ocr.cargoffer.com/api/upload")
.header("Authorization", format!("Bearer {}", api_key))
.multipart(form)
.send().await?.json().await?;
// Analyze
let result = client
.post(format!("https://ocr.cargoffer.com/api/analyze/{}", upload.job))
.header("Authorization", format!("Bearer {}", api_key))
.send().await?.text().await?;
println!("Extracted: {}", result);
Ok(())
}