flarer 0.1.0

Rust client and CLI for Cloudflare's Browser Rendering REST API (content, screenshot, PDF, snapshot, markdown, scrape, JSON extraction, links, crawl).
Documentation
//! Use the JSON tool with a custom JSON Schema.

use flarer::{Account, Flarer, JsonOptions, ResponseFormat};
use serde_json::json;

#[tokio::main]
async fn main() -> flarer::Result<()> {
    let url = std::env::args()
        .nth(1)
        .unwrap_or_else(|| "https://example.com".to_string());

    let schema = json!({
        "type": "object",
        "properties": {
            "title": { "type": "string" },
            "links": {
                "type": "array",
                "items": { "type": "string" }
            }
        },
        "required": ["title"]
    });

    let account = Account::from_env()?;
    let flarer = Flarer::builder().account(account).build()?;

    let opts = JsonOptions::new()
        .with_prompt("Extract the page title and all hyperlinks.")
        .with_response_format(ResponseFormat::json_schema(schema));

    let value = flarer.json(&url, opts).await?;
    println!("{}", serde_json::to_string_pretty(&value)?);
    Ok(())
}