Skip to content

Rust client for screenshotbase.com API (status + /v1/take)

License

Notifications You must be signed in to change notification settings

everapihq/screenshotbase-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

screenshotbase (Rust)

Rust client for the screenshotbase.com API to:

  • Retrieve API status and quota
  • Take a website screenshot to image/PDF bytes

API docs: https://screenshotbase.com/docs/ Register API key: https://screenshotbase.com

Features

  • Async client via reqwest
  • Optional blocking client behind blocking feature
  • Configurable base_url (defaults to https://api.screenshotbase.com)
  • Authentication via X-API-Key header and api_key query param

Install

[dependencies]
screenshotbase = { path = "./screenshotbase-crates" }

Or from your own registry/workspace as desired.

Enable blocking client:

[dependencies]
screenshotbase = { path = "./screenshotbase-crates", features = ["blocking"] }

Quickstart (async)

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let api_key = std::env::var("SCREENSHOTBASE_API_KEY")?;
    let client = screenshotbase::client::ScreenshotbaseClient::new(api_key)?;

    // Status
    let status = client.get_status().await?;
    println!("Plan: {:?}, Quota used: {:?}", status.plan, status.quota_used);

    // Take website screenshot
    let result = client
        .take_screenshot(
            "https://example.com",
            screenshotbase::types::RenderOptions {
                format: Some(screenshotbase::types::ImageFormat::Png),
                full_page: Some(true),
                width: Some(1280),
                height: Some(800),
                ..Default::default()
            },
        )
        .await?;
    println!("Content-Type: {:?}", result.content_type);
    println!("Received {} bytes", result.bytes.len());
    Ok(())
}

Blocking

fn main() -> Result<(), Box<dyn std::error::Error>> {
    #[cfg(feature = "blocking")]
    {
        let api_key = std::env::var("SCREENSHOTBASE_API_KEY")?;
        let client = screenshotbase::client::ScreenshotbaseBlockingClient::new(api_key)?;
        let status = client.get_status()?;
        println!("Plan: {:?}", status.plan);
        let _result = client.take_screenshot("https://example.com", screenshotbase::types::RenderOptions::default())?;
    }
    Ok(())
}

Notes

  • Endpoints implemented:
    • GET /v1/status
    • GET /v1/take?url=... with additional query parameters from RenderOptions
  • The default base URL is https://api.screenshotbase.com; override with .with_base_url(...) if necessary.
  • Authentication uses X-API-Key header and also appends api_key as a query parameter for compatibility.

Refer to the official docs for details and the latest parameters: https://screenshotbase.com/docs/

License

MIT

About

Rust client for screenshotbase.com API (status + /v1/take)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages