Expand description
The official async Rust SDK for the Wellfriend document API.
use wellfriend::Wellfriend;
let wf = Wellfriend::new();
wf.tools().compress_pdf("in.pdf", None).await?.save("out.pdf").await?;§What is in the box
Wellfriend::tools: one typed method per document tool. Each method uploads the input, starts the operation, waits for it and returns aToolResultyou can save or stream.Wellfriend::pipeline: several tools on one file, each step reading the previous output.- Typed resources for every endpoint, for example
Wellfriend::documentsandWellfriend::document_operations. List calls return aPage; the matchingstreammethod pages through everything. - Streaming uploads (direct up to 100 MiB, resumable multipart above) and streaming downloads.
- Automatic retries with exponential backoff and idempotency keys, per-request
RequestOptions, and oneErrortype. verify_webhookfor signed webhook deliveries, returning a typedWebhookEvent.
§Configuration
Wellfriend::new reads WELLFRIEND_API_KEY (and optionally WELLFRIEND_BASE_URL) from the
environment. Use Wellfriend::builder to set the key, base URL, timeout, retries, wait limit
or your own reqwest::Client.
§Cancellation
Every call is a future: dropping it cancels the request. Wrap a call in
tokio::time::timeout to bound the whole call, including waiting for an operation.
Re-exports§
pub use generated::events::WebhookEventData;pub use generated::models::*;pub use generated::resources::*;pub use generated::tools::*;
Modules§
- generated
- Code generated from the API document and the tool catalog.
- types
- Every model in one place: tool parameters (for example
types::CompressPdfParams) and their choice enums, request and response types, the core resources and webhook payloads. The same items are also exported at the crate root.
Structs§
- ApiError
- An error response from the API.
- Defined
Workflow - A workflow defined from tool steps, reusable like a tool.
- Document
- A document stored in the workspace.
- Document
Version - One immutable version of a document.
- Download
- A file download, streamed from the API. Nothing is buffered until you ask for it.
- File
Input - A file to process: a local path, bytes in memory, an async reader, or a document that is already stored.
- Operation
- A document operation: one tool run on one or more document versions.
- Operation
Failure - Why an operation or workflow run failed.
- Operation
Outputs - The outputs of an operation.
- Output
- One output file of an operation.
- Page
- One page of a list.
- Pipeline
- Several tools run one after another on one file.
- Request
Options - Settings for one call, applied with
with_optionson any resource handle. - Step
- One step of a pipeline: a tool and its parameters.
- Tool
Embed Session - The fields of a TOOL embed session: one tool workspace in your page, charged like the API.
- Tool
Input - The input of a tool run: one file, or several for tools that read several (merge-pdf, image-to-pdf).
- Tool
Parameters - Tool parameters as a JSON object. Every generated
...Paramsstruct converts into it; use it directly for options this SDK version does not model yet. - Tool
Request - A tool call with every option: inputs, parameters and named assets.
- Tool
Result - The result of a finished tool run or pipeline.
- Tool
Usage - Request units and credits a tool run used, when the API reports them.
- Tools
- Access to the document tools. Get it with
Wellfriend::tools. - Version
Ref - A document version reference.
- Webhook
Event - A verified webhook event (CloudEvents 1.0).
- Webhook
Event Meta - The
wellfriendextension of every event. - Webhook
Verifier - A webhook verifier with one or more secrets and a configurable tolerance.
- Webhooks
- Webhook helpers on the client. Get it with
Wellfriend::webhooks. - Wellfriend
- The Wellfriend API client.
- Wellfriend
Builder - Builds a
Wellfriendclient. - Workflow
- A workflow definition.
- Workflow
Run - One run of a workflow.
- Workflow
Step - One step of a workflow run.
Enums§
- Asset
- A named asset file a tool reads (a watermark image, a signature image, a certificate).
- Error
- Every error this SDK returns.
- Operation
State - The state of a document operation.
- Output
Kind - Where an operation’s output went.
- RunState
- The state of a workflow run or step.
- Upload
Completion - The answer to completing a resumable upload.
- Value
- Re-exported so callers can match on JSON values without adding
serde_jsonthemselves. Represents any valid JSON value. - Workflow
Status - The status of a workflow definition.
Constants§
- CHECKSUM_
REQUIRED_ ABOVE_ BYTES - Above this size (50 MiB) a resumable upload must declare the file’s SHA-256.
- DEFAULT_
BASE_ URL - The API base URL used when neither the builder nor
WELLFRIEND_BASE_URLsets one. - MAX_
PIPELINE_ STEPS - The most steps one pipeline may have.
- SINGLE_
REQUEST_ MAX_ BYTES - The largest body one upload request may carry (100 MiB). Larger files use the resumable flow.
- VERSION
- This crate’s version, sent in the
User-Agentheader. - WEBHOOK_
TOLERANCE - How far a delivery’s timestamp may be from now (5 minutes).
Traits§
- Webhook
Headers - Request headers, from any HTTP framework.
Functions§
- verify_
webhook - Verifies a webhook delivery and returns the typed event.
Type Aliases§
- Object
- A JSON object, used where the API document does not describe a response in detail.
- Page
Stream - Every item of a list, fetching the following pages as you consume it.
- Result
- The result type of every fallible call in this crate.