img_src 0.2.1

Rust SDK for img-src image processing and delivery API
Documentation

img-src Rust SDK

Developer-friendly & type-safe Rust SDK specifically catered to leverage img-src API.

Crates.io docs.rs License: MIT

Summary

img-src API: Image processing and delivery API.

A serverless image processing and delivery API built on Cloudflare Workers with parameter-driven image transformation and on-demand transcoding.

Features

  • Image Upload: Store original images in R2 with SHA256-based deduplication
  • On-Demand Transformation: Resize, crop, and convert images via URL parameters
  • Format Conversion: WebP, AVIF, JPEG, PNG output formats
  • Path Organization: Organize images into folders with multiple paths per image
  • CDN Caching: Automatic edge caching for transformed images

Authentication

Authenticate using API Keys with imgsrc_ prefix. Create your API key at https://img-src.io/settings

Rate Limiting

  • Free Plan: 100 requests/minute
  • Pro Plan: 500 requests/minute

Rate limit headers are included in all responses.

Table of Contents

SDK Installation

Add the SDK as a dependency to your Cargo.toml:

[dependencies]
img_src = "0.2.0"

Or install via cargo:

cargo add img_src

SDK Example Usage

Upload and Transform Images

use img_src::apis::configuration::Configuration;
use img_src::apis::images_api;
use std::env;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create API key at https://img-src.io/settings
    let mut config = Configuration::new();
    config.bearer_access_token = Some(env::var("IMGSRC_API_KEY")?);

    // List images
    let images = images_api::list_images(&config, Some(20), None, None).await?;
    println!("Total: {:?} images", images.total);

    // Access with transformations via CDN
    // https://img-src.io/i/{username}/photos/2024/photo.webp?w=800&h=600&fit=cover&q=85

    Ok(())
}

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

Name Type Scheme
BearerAuth http HTTP Bearer

You can configure it by setting the bearer_access_token field in the Configuration struct. For example:

use img_src::apis::configuration::Configuration;
use img_src::apis::settings_api;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut config = Configuration::new();
    config.bearer_access_token = Some(env::var("IMGSRC_API_KEY")?);

    let settings = settings_api::get_settings(&config).await?;
    println!("{:?}", settings);

    Ok(())
}

Create your API key at https://img-src.io/settings.

Available Resources and Operations

Images

Presets

Settings

Usage

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a Result type, they will never panic.

By default, an API error will return Error<T>. You can handle errors using pattern matching:

use img_src::apis::configuration::Configuration;
use img_src::apis::settings_api;

#[tokio::main]
async fn main() {
    let mut config = Configuration::new();
    config.bearer_access_token = Some("your_api_key".to_string());

    match settings_api::get_settings(&config).await {
        Ok(settings) => println!("Settings: {:?}", settings),
        Err(e) => eprintln!("Error: {:?}", e),
    }
}

Server Selection

Override Server URL Per-Client

The default server can be overridden globally by setting the base_path field in the Configuration struct. For example:

use img_src::apis::configuration::Configuration;

let mut config = Configuration::new();
config.base_path = "https://api.img-src.io".to_string();
config.bearer_access_token = Some("your_api_key".to_string());

Custom HTTP Client

The Rust SDK makes API calls using reqwest. You can customize the HTTP client by providing your own reqwest::Client instance:

use img_src::apis::configuration::Configuration;
use reqwest::Client;
use std::time::Duration;

let http_client = Client::builder()
    .timeout(Duration::from_secs(30))
    .build()
    .unwrap();

let mut config = Configuration::new();
config.client = http_client;
config.bearer_access_token = Some("your_api_key".to_string());

This can be a convenient way to configure timeouts, proxies, custom headers, and other low-level configuration.

Documentation For Models

To get access to the crate's generated documentation, use:

cargo doc --open

Development

Maturity

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Contributions

While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.

Author

Taehun

For more information, please visit https://docs.img-src.io