API2Convert Rust SDK
Official Rust SDK for the API2Convert file-conversion API.
One call uploads (or references a URL), starts the job, polls it to completion and hands you the
result. It is one of the official API2Convert SDKs (PHP, Python, Java, Node.js, Go, Ruby, Rust) that
implement the same language-agnostic contract (docs/SDK_CONTRACT.md) and
version together.
- Blocking / synchronous API (like the Python, Go, Java, Ruby and PHP SDKs).
- Lean dependencies —
reqwest,serde_json,hmac,sha2. - Secure by construction — secret headers never cross a redirect, uploads use the per-job token
(never the account key), and no secret ever appears in an error. See
SECURITY.md.
Install
[]
= "10"
Requires Rust 1.86+ (set by the reqwest dependency tree).
Quickstart
use Api2Convert;
The API key also comes from the API2CONVERT_API_KEY environment variable:
let client = from_env?;
Inputs
convert accepts a local path, a remote URL, in-memory bytes, or a streaming reader. A string
starting with http:// / https:// is treated as a URL (sent as a remote input); anything else is a
local path.
client.convert?; // remote URL
client.convert?; // local path
client.convert?; // bytes
client.convert?; // stream
Conversion options
Target-specific options are a separate map from the SDK controls, so an API option key can never collide with an SDK argument:
use ;
let result = client.convert_with?;
let bytes = result.contents?;
Discover the valid options for a target:
let options = client.options?;
Download password
A password given at conversion time is remembered on the result and applied automatically:
use ;
let result = client.convert_with?;
result.save?; // password applied automatically
Async (start now, download later / via webhook)
use ;
let job = client.convert_async_with?;
println!;
Verify the webhook delivery in your handler (pass the raw request body and the X-Oc-Signature
header):
use Api2Convert;
let event = webhooks.construct_event?;
println!;
Errors
Every fallible call returns Result<_, Api2ConvertError>. Match it to react to specific conditions:
use ;
match client.convert
HTTP-error variants expose status(), request_id() (the X-Request-Id) and body().
Full lifecycle control
convert is built on the jobs() resource, which you can drive directly:
use Api2Convert;
use json;
let job = client.jobs.create?;
client.jobs.upload?;
client.jobs.start?;
let job = client.jobs.wait?;
let outputs = client.jobs.outputs?;
Other resources: conversions(), presets(), stats(), contracts().
Configuration
use Duration;
use Api2Convert;
let client = builder
.api_key
.timeout
.max_retries
.poll_interval
.poll_timeout
.build?;
| Knob | Default | Notes |
|---|---|---|
base_url |
https://api.api2convert.com/v2 |
trailing / trimmed |
timeout |
30s | JSON requests; min 1s |
max_retries |
2 | transient failures |
poll_interval |
1s | floored to 500ms |
poll_max_interval |
5s | backoff ceiling |
poll_timeout |
300s | capped at 14400s (4h) |
max_download_bytes |
0 (unlimited) | cap downloaded size |
Testing
API2CONVERT_API_KEY=<key> cargo
License
MIT © Qaamgo Media GmbH.