Rust client
Install, configure, and call Insion from asynchronous Rust applications.
The Rust SDK exposes an async ApiClient, typed request/response models, builders for required fields, and ApiError for all failures. The crate is built on Tokio and reqwest; every client operation returns Result<T, ApiError> and must be awaited.
Install and initialize
Add the published crate to your project, then import its prelude:
cargo add insion_apiuse insion_api::prelude::*;
#[tokio::main]
async fn main() -> Result<(), ApiError> {
let client = ApiClientBuilder::default()
.token("<token>")
.build()?;
let response = client
.moderate_a_record(
&ModerateRequest::builder()
.client_id("post-123")
.name("Welcome post")
.entity("post")
.content(Content::String("Hello from Rust".to_string()))
.build()?,
None,
)
.await?;
println!("{}", response.id);
Ok(())
}The builder is the safest way to construct requests: it returns BuildError if a required field was not supplied. The public fields on generated models are also usable directly when that better suits your codebase.
Select an operation
Use moderate_a_record for a decision in the current request. Use ingest_a_record when moderation is asynchronous and the result will arrive through webhooks. ingest_a_user updates user data without a record. The list/retrieve calls inspect stored resources, and create_an_appeal submits an appeal for an eligible suspended user.
clientId is your own stable identifier. Insion also returns an id for each record or user; these are intentionally different. Retrieval, list cursors, user filters, and appeals use Insion IDs, while record deletion uses the original clientId.
Models, content, and metadata
Content is an enum. Use Content::String for plain text or Content::ContentExternalUrls for text with image/page URLs. The latter has a required text field:
let content = Content::ContentExternalUrls(
ContentExternalUrls::builder()
.text("Review this listing")
.image_urls(vec!["https://cdn.example.com/image.png".to_string()])
.build()?
);Metadata is a map of JSON values. Keys can be at most 40 characters and cannot include [ or ]; values must be serializable and at most 500 characters, and an object can hold at most 50 keys. See Configuration and Errors before integrating the client into a retrying service.