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
- Async client via
reqwest - Optional blocking client behind
blockingfeature - Configurable
base_url(defaults tohttps://api.screenshotbase.com) - Authentication via
X-API-Keyheader andapi_keyquery param
[dependencies]
screenshotbase = { path = "./screenshotbase-crates" }Or from your own registry/workspace as desired.
Enable blocking client:
[dependencies]
screenshotbase = { path = "./screenshotbase-crates", features = ["blocking"] }#[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(())
}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(())
}- Endpoints implemented:
GET /v1/statusGET /v1/take?url=...with additional query parameters fromRenderOptions
- The default base URL is
https://api.screenshotbase.com; override with.with_base_url(...)if necessary. - Authentication uses
X-API-Keyheader and also appendsapi_keyas a query parameter for compatibility.
Refer to the official docs for details and the latest parameters: https://screenshotbase.com/docs/
MIT