pub struct Client { /* private fields */ }Expand description
Scrapfly API client. Cheap to Clone (the inner reqwest::Client is
Arc’d so all clones share one connection pool).
Implementations§
Source§impl Client
impl Client
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Start a new ClientBuilder.
Sourcepub fn cloud_browser_host(&self) -> &str
pub fn cloud_browser_host(&self) -> &str
Return the configured Cloud Browser host.
Sourcepub async fn verify_api_key(&self) -> Result<VerifyApiKeyResult, ScrapflyError>
pub async fn verify_api_key(&self) -> Result<VerifyApiKeyResult, ScrapflyError>
Verify the API key by hitting /account.
Sourcepub async fn account(&self) -> Result<AccountData, ScrapflyError>
pub async fn account(&self) -> Result<AccountData, ScrapflyError>
Fetch account info.
Sourcepub async fn classify(
&self,
req: &ClassifyRequest,
) -> Result<ClassifyResult, ScrapflyError>
pub async fn classify( &self, req: &ClassifyRequest, ) -> Result<ClassifyResult, ScrapflyError>
Classify an already-fetched HTTP response for anti-bot blocking.
Runs the same detection pipeline used by every live Scrapfly scrape against a response you already have (from your own proxy, cache, etc). 1 API credit per successful call. See https://scrapfly.io/docs/scrape-api/classify.
Sourcepub async fn get_monitoring_metrics(
&self,
opts: &MonitoringMetricsOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_monitoring_metrics( &self, opts: &MonitoringMetricsOptions, ) -> Result<Value, ScrapflyError>
Fetch aggregate monitoring metrics for the Web Scraping API.
Sourcepub async fn get_monitoring_target_metrics(
&self,
opts: &MonitoringTargetMetricsOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_monitoring_target_metrics( &self, opts: &MonitoringTargetMetricsOptions, ) -> Result<Value, ScrapflyError>
Fetch per-target monitoring metrics for the Web Scraping API.
Sourcepub async fn get_screenshot_monitoring_metrics(
&self,
opts: &MonitoringMetricsOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_screenshot_monitoring_metrics( &self, opts: &MonitoringMetricsOptions, ) -> Result<Value, ScrapflyError>
Fetch aggregate monitoring metrics for the Screenshot API.
Sourcepub async fn get_screenshot_monitoring_target_metrics(
&self,
opts: &MonitoringTargetMetricsOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_screenshot_monitoring_target_metrics( &self, opts: &MonitoringTargetMetricsOptions, ) -> Result<Value, ScrapflyError>
Fetch per-target monitoring metrics for the Screenshot API.
Sourcepub async fn get_extraction_monitoring_metrics(
&self,
opts: &MonitoringMetricsOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_extraction_monitoring_metrics( &self, opts: &MonitoringMetricsOptions, ) -> Result<Value, ScrapflyError>
Fetch aggregate monitoring metrics for the Extraction API.
Sourcepub async fn get_extraction_monitoring_target_metrics(
&self,
opts: &MonitoringTargetMetricsOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_extraction_monitoring_target_metrics( &self, opts: &MonitoringTargetMetricsOptions, ) -> Result<Value, ScrapflyError>
Fetch per-target monitoring metrics for the Extraction API.
Sourcepub async fn get_crawler_monitoring_metrics(
&self,
opts: &MonitoringMetricsOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_crawler_monitoring_metrics( &self, opts: &MonitoringMetricsOptions, ) -> Result<Value, ScrapflyError>
Fetch aggregate monitoring metrics for the Crawler API.
Sourcepub async fn get_crawler_monitoring_target_metrics(
&self,
opts: &MonitoringTargetMetricsOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_crawler_monitoring_target_metrics( &self, opts: &MonitoringTargetMetricsOptions, ) -> Result<Value, ScrapflyError>
Fetch per-target monitoring metrics for the Crawler API.
Sourcepub async fn get_browser_monitoring_metrics(
&self,
opts: &CloudBrowserMonitoringOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_browser_monitoring_metrics( &self, opts: &CloudBrowserMonitoringOptions, ) -> Result<Value, ScrapflyError>
Fetch aggregate monitoring metrics for the Cloud Browser API.
Sourcepub async fn get_browser_monitoring_timeseries(
&self,
opts: &CloudBrowserMonitoringOptions,
) -> Result<Value, ScrapflyError>
pub async fn get_browser_monitoring_timeseries( &self, opts: &CloudBrowserMonitoringOptions, ) -> Result<Value, ScrapflyError>
Fetch monitoring time-series for the Cloud Browser API.
Sourcepub async fn scrape(
&self,
config: &ScrapeConfig,
) -> Result<ScrapeResult, ScrapflyError>
pub async fn scrape( &self, config: &ScrapeConfig, ) -> Result<ScrapeResult, ScrapflyError>
Scrape a URL.
Sourcepub fn concurrent_scrape<'a, I>(
&'a self,
configs: I,
concurrency_limit: usize,
) -> impl Stream<Item = Result<ScrapeResult, ScrapflyError>> + 'a
pub fn concurrent_scrape<'a, I>( &'a self, configs: I, concurrency_limit: usize, ) -> impl Stream<Item = Result<ScrapeResult, ScrapflyError>> + 'a
Concurrent-scrape stream. Emits results in completion order.
Sourcepub async fn scrape_batch(
&self,
configs: &[ScrapeConfig],
) -> Result<impl Stream<Item = (String, BatchOutcome)>, ScrapflyError>
pub async fn scrape_batch( &self, configs: &[ScrapeConfig], ) -> Result<impl Stream<Item = (String, BatchOutcome)>, ScrapflyError>
POST /scrape/batch: scrape up to 100 URLs and stream results
back as each scrape completes. Returns an async stream where
each item is (correlation_id, Result<ScrapeResult, ScrapflyError>).
Results arrive OUT OF ORDER — whichever scrape finishes first
is yielded first. Every ScrapeConfig MUST carry a unique
correlation_id; missing / duplicate values are caught
client-side before the request is sent.
Batch-level failures (plan gate, insufficient concurrency,
validation) surface as the outer Err(ScrapflyError) returned
from the await — the stream is only created after the
batch request succeeds.
Sourcepub async fn scrape_batch_with_options(
&self,
configs: &[ScrapeConfig],
opts: BatchOptions,
) -> Result<impl Stream<Item = (String, BatchOutcome)>, ScrapflyError>
pub async fn scrape_batch_with_options( &self, configs: &[ScrapeConfig], opts: BatchOptions, ) -> Result<impl Stream<Item = (String, BatchOutcome)>, ScrapflyError>
Like scrape_batch but with explicit BatchOptions
(msgpack wire format, etc.).
Sourcepub async fn scrape_proxified(
&self,
config: &ScrapeConfig,
) -> Result<Response, ScrapflyError>
pub async fn scrape_proxified( &self, config: &ScrapeConfig, ) -> Result<Response, ScrapflyError>
Scrape a URL with proxified_response=true, returning the raw
upstream reqwest::Response (target’s status, headers, body).
Unlike [scrape()], no JSON parsing occurs — the response body is
the target page’s raw content. Scrapfly metadata is available on
the X-Scrapfly-* response headers (Api-Cost, Content-Format,
Log, etc.).
Automatically forces proxified_response=true regardless of the
config’s field value.
Sourcepub async fn screenshot(
&self,
config: &ScreenshotConfig,
) -> Result<ScreenshotResult, ScrapflyError>
pub async fn screenshot( &self, config: &ScreenshotConfig, ) -> Result<ScreenshotResult, ScrapflyError>
Screenshot a URL.
Sourcepub async fn extract(
&self,
config: &ExtractionConfig,
) -> Result<ExtractionResult, ScrapflyError>
pub async fn extract( &self, config: &ExtractionConfig, ) -> Result<ExtractionResult, ScrapflyError>
Run AI extraction on a document.
Sourcepub async fn start_crawl(
&self,
config: &CrawlerConfig,
) -> Result<CrawlerStartResponse, ScrapflyError>
pub async fn start_crawl( &self, config: &CrawlerConfig, ) -> Result<CrawlerStartResponse, ScrapflyError>
Schedule a new crawler job.
POST /crawl accepts two body formats:
application/json— the entire crawler configuration as JSON. Used for seed-URL crawls andremote_url_listcrawls.multipart/form-data— aconfigJSON part and aurlstext part (one URL per line). Used only when the caller provides an in-memoryurl_list, so the URLs are uploaded as a streamed file payload instead of inlined into the JSON body.
Sourcepub async fn crawl_status(
&self,
uuid: &str,
) -> Result<CrawlerStatus, ScrapflyError>
pub async fn crawl_status( &self, uuid: &str, ) -> Result<CrawlerStatus, ScrapflyError>
Fetch crawler status.
Sourcepub async fn crawl_urls(
&self,
uuid: &str,
status_filter: Option<&str>,
page: u32,
per_page: u32,
) -> Result<CrawlerUrls, ScrapflyError>
pub async fn crawl_urls( &self, uuid: &str, status_filter: Option<&str>, page: u32, per_page: u32, ) -> Result<CrawlerUrls, ScrapflyError>
List crawled URLs (streaming text endpoint).
Sourcepub async fn crawl_contents_json(
&self,
uuid: &str,
format: CrawlerContentFormat,
limit: Option<u32>,
offset: Option<u32>,
) -> Result<CrawlerContents, ScrapflyError>
pub async fn crawl_contents_json( &self, uuid: &str, format: CrawlerContentFormat, limit: Option<u32>, offset: Option<u32>, ) -> Result<CrawlerContents, ScrapflyError>
Bulk GET /crawl/{uuid}/contents in JSON mode.
Sourcepub async fn crawl_contents_plain(
&self,
uuid: &str,
target_url: &str,
format: CrawlerContentFormat,
) -> Result<String, ScrapflyError>
pub async fn crawl_contents_plain( &self, uuid: &str, target_url: &str, format: CrawlerContentFormat, ) -> Result<String, ScrapflyError>
Plain single-URL GET /crawl/{uuid}/contents?plain=true.
Sourcepub async fn crawl_contents_batch(
&self,
uuid: &str,
urls: &[String],
formats: &[CrawlerContentFormat],
) -> Result<BTreeMap<String, BTreeMap<String, String>>, ScrapflyError>
pub async fn crawl_contents_batch( &self, uuid: &str, urls: &[String], formats: &[CrawlerContentFormat], ) -> Result<BTreeMap<String, BTreeMap<String, String>>, ScrapflyError>
Bulk-batch POST /crawl/{uuid}/contents/batch.
Returns url → format → content (multipart/related response).
Sourcepub async fn crawl_cancel(&self, uuid: &str) -> Result<(), ScrapflyError>
pub async fn crawl_cancel(&self, uuid: &str) -> Result<(), ScrapflyError>
Cancel a crawler job.
Sourcepub async fn crawl_artifact(
&self,
uuid: &str,
artifact_type: CrawlerArtifactType,
) -> Result<CrawlerArtifact, ScrapflyError>
pub async fn crawl_artifact( &self, uuid: &str, artifact_type: CrawlerArtifactType, ) -> Result<CrawlerArtifact, ScrapflyError>
Download a crawler artifact (WARC or HAR).
Source§impl Client
impl Client
Sourcepub fn cloud_browser_url(&self, config: &BrowserConfig) -> String
pub fn cloud_browser_url(&self, config: &BrowserConfig) -> String
Build the WebSocket URL for a new Cloud Browser session.
On rejection the server sends a JSON error frame then a close frame with code 1008/1011/1013 and a “ERR::BROWSER::CODE: reason” string. See https://scrapfly.io/docs/cloud-browser-api/errors#websocket-close-frame
Sourcepub fn cloud_browser_project_salt(&self) -> String
pub fn cloud_browser_project_salt(&self) -> String
Return the deterministic project salt for this client’s api key.
Matches the X-Browser-Project-Salt response header.
Sourcepub async fn cloud_browser_unblock(
&self,
config: &UnblockConfig,
) -> Result<UnblockResult, ScrapflyError>
pub async fn cloud_browser_unblock( &self, config: &UnblockConfig, ) -> Result<UnblockResult, ScrapflyError>
Call POST /unblock to bypass anti-bot protection.
Sourcepub async fn cloud_browser_extension_list(&self) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_extension_list(&self) -> Result<Value, ScrapflyError>
List browser extensions for the account.
Sourcepub async fn cloud_browser_extension_get(
&self,
extension_id: &str,
) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_extension_get( &self, extension_id: &str, ) -> Result<Value, ScrapflyError>
Get details of a specific browser extension.
Sourcepub async fn cloud_browser_extension_upload(
&self,
file_path: &Path,
) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_extension_upload( &self, file_path: &Path, ) -> Result<Value, ScrapflyError>
Upload a browser extension from a local file (.zip or .crx).
Sourcepub async fn cloud_browser_extension_delete(
&self,
extension_id: &str,
) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_extension_delete( &self, extension_id: &str, ) -> Result<Value, ScrapflyError>
Delete a browser extension by ID.
Sourcepub async fn cloud_browser_vault_create(
&self,
name: &str,
description: Option<&str>,
) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_vault_create( &self, name: &str, description: Option<&str>, ) -> Result<Value, ScrapflyError>
Create a new credential vault. The server returns a freshly
generated vault key under the key field of the response — this
is the only time the key is shown. Save it locally; the server
cannot recover it.
Sourcepub async fn cloud_browser_vault_list(&self) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_vault_list(&self) -> Result<Value, ScrapflyError>
List all credential vaults for the account.
Sourcepub async fn cloud_browser_vault_get(
&self,
vault_id: &str,
) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_vault_get( &self, vault_id: &str, ) -> Result<Value, ScrapflyError>
Get vault metadata. Does NOT include any secret material.
Sourcepub async fn cloud_browser_vault_update(
&self,
vault_id: &str,
name: Option<&str>,
description: Option<&str>,
) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_vault_update( &self, vault_id: &str, name: Option<&str>, description: Option<&str>, ) -> Result<Value, ScrapflyError>
Rename a vault (and/or update its description). Only the
non-None fields are sent.
Sourcepub async fn cloud_browser_vault_delete(
&self,
vault_id: &str,
) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_vault_delete( &self, vault_id: &str, ) -> Result<Value, ScrapflyError>
Delete a vault by id (cascades to all items).
Sourcepub async fn cloud_browser_vault_rotate(
&self,
vault_id: &str,
current_vault_key: &str,
) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_vault_rotate( &self, vault_id: &str, current_vault_key: &str, ) -> Result<Value, ScrapflyError>
Rotate a vault’s key. Requires the CURRENT key in the
X-Vault-Key header; the server returns a fresh key in the
response body. After this call the old key is permanently
invalid for this vault. The current key is forwarded to the
server transiently and never logged by the SDK.
Sourcepub async fn cloud_browser_vault_item_list(
&self,
vault_id: &str,
) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_vault_item_list( &self, vault_id: &str, ) -> Result<Value, ScrapflyError>
List items in a vault. Items include the encrypted secret_blob
but not plaintext — the blob is meaningless without the
customer-held key.
Sourcepub async fn cloud_browser_vault_item_create(
&self,
vault_id: &str,
vault_key: &str,
item: Value,
) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_vault_item_create( &self, vault_id: &str, vault_key: &str, item: Value, ) -> Result<Value, ScrapflyError>
Create a new item in a vault. The vault key is required to
envelope-encrypt the per-item DEK; it is forwarded transiently
in the X-Vault-Key header. Caller-supplied item JSON shape
follows the documented contract (see itemCreateRequest in
pkg/vault/controller.go) — typically:
{
"type": "password",
"label": "...",
"origin": "https://example.com",
"username": "user",
"secret": {"password": "hunter2"}
}Sourcepub async fn cloud_browser_vault_item_update(
&self,
vault_id: &str,
item_id: &str,
vault_key: Option<&str>,
patch: Value,
) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_vault_item_update( &self, vault_id: &str, item_id: &str, vault_key: Option<&str>, patch: Value, ) -> Result<Value, ScrapflyError>
Patch an existing item. vault_key is REQUIRED iff the patch
rotates the secret payload (i.e. secret is present in
patch); for pure metadata edits (label, origin, username,
metadata) the server accepts the request without an
X-Vault-Key header. The SDK forwards the key only when
supplied — it does not auto-detect the patch shape.
Sourcepub async fn cloud_browser_vault_item_delete(
&self,
vault_id: &str,
item_id: &str,
) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_vault_item_delete( &self, vault_id: &str, item_id: &str, ) -> Result<Value, ScrapflyError>
Delete a single vault item.
Sourcepub async fn cloud_browser_playback(
&self,
run_id: &str,
) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_playback( &self, run_id: &str, ) -> Result<Value, ScrapflyError>
Get debug recording playback metadata for a run. The response carries
available, status (one of ready, uploading, unavailable,
disabled), metadata, video_url, and retry_after_ms.
Sourcepub async fn cloud_browser_wait_for_playback(
&self,
run_id: &str,
timeout: Duration,
fallback_interval: Duration,
) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_wait_for_playback( &self, run_id: &str, timeout: Duration, fallback_interval: Duration, ) -> Result<Value, ScrapflyError>
Poll the playback endpoint until the recording resolves to a terminal
state (ready or unavailable) or the timeout elapses. Honours the
server’s retry_after_ms hint when present.
Sourcepub async fn cloud_browser_session_stop(
&self,
session_id: &str,
) -> Result<(), ScrapflyError>
pub async fn cloud_browser_session_stop( &self, session_id: &str, ) -> Result<(), ScrapflyError>
Terminate a Cloud Browser session.
Sourcepub async fn cloud_browser_sessions(&self) -> Result<Value, ScrapflyError>
pub async fn cloud_browser_sessions(&self) -> Result<Value, ScrapflyError>
List all running Cloud Browser sessions.
Sourcepub async fn cloud_browser_video(
&self,
run_id: &str,
) -> Result<Vec<u8>, ScrapflyError>
pub async fn cloud_browser_video( &self, run_id: &str, ) -> Result<Vec<u8>, ScrapflyError>
Download a debug session recording video (raw bytes).
Source§impl Client
impl Client
Sourcepub async fn create_scrape_schedule(
&self,
scrape_config: HashMap<String, Value>,
request: &CreateScheduleRequest,
) -> Result<Schedule, ScrapflyError>
pub async fn create_scrape_schedule( &self, scrape_config: HashMap<String, Value>, request: &CreateScheduleRequest, ) -> Result<Schedule, ScrapflyError>
Create a Web Scraping API schedule.
Sourcepub async fn create_screenshot_schedule(
&self,
screenshot_config: HashMap<String, Value>,
request: &CreateScheduleRequest,
) -> Result<Schedule, ScrapflyError>
pub async fn create_screenshot_schedule( &self, screenshot_config: HashMap<String, Value>, request: &CreateScheduleRequest, ) -> Result<Schedule, ScrapflyError>
Create a Screenshot API schedule.
Sourcepub async fn create_crawler_schedule(
&self,
crawler_config: HashMap<String, Value>,
request: &CreateScheduleRequest,
) -> Result<Schedule, ScrapflyError>
pub async fn create_crawler_schedule( &self, crawler_config: HashMap<String, Value>, request: &CreateScheduleRequest, ) -> Result<Schedule, ScrapflyError>
Create a Crawler API schedule.
Sourcepub async fn get_schedule(&self, id: &str) -> Result<Schedule, ScrapflyError>
pub async fn get_schedule(&self, id: &str) -> Result<Schedule, ScrapflyError>
Return a schedule by id (works across all kinds).
Sourcepub async fn list_schedules(
&self,
opts: Option<&ListSchedulesOptions>,
) -> Result<Vec<Schedule>, ScrapflyError>
pub async fn list_schedules( &self, opts: Option<&ListSchedulesOptions>, ) -> Result<Vec<Schedule>, ScrapflyError>
List every schedule on the account, optionally filtered by kind/status.
Sourcepub async fn list_scrape_schedules(
&self,
status: Option<&str>,
) -> Result<Vec<Schedule>, ScrapflyError>
pub async fn list_scrape_schedules( &self, status: Option<&str>, ) -> Result<Vec<Schedule>, ScrapflyError>
List scrape schedules, optionally filtered by status.
Sourcepub async fn list_screenshot_schedules(
&self,
status: Option<&str>,
) -> Result<Vec<Schedule>, ScrapflyError>
pub async fn list_screenshot_schedules( &self, status: Option<&str>, ) -> Result<Vec<Schedule>, ScrapflyError>
List screenshot schedules, optionally filtered by status.
Sourcepub async fn list_crawler_schedules(
&self,
status: Option<&str>,
) -> Result<Vec<Schedule>, ScrapflyError>
pub async fn list_crawler_schedules( &self, status: Option<&str>, ) -> Result<Vec<Schedule>, ScrapflyError>
List crawler schedules, optionally filtered by status.
Sourcepub async fn update_schedule(
&self,
id: &str,
request: &UpdateScheduleRequest,
) -> Result<Schedule, ScrapflyError>
pub async fn update_schedule( &self, id: &str, request: &UpdateScheduleRequest, ) -> Result<Schedule, ScrapflyError>
Patch an active schedule. Only fields set in request change.
Sourcepub async fn cancel_schedule(&self, id: &str) -> Result<(), ScrapflyError>
pub async fn cancel_schedule(&self, id: &str) -> Result<(), ScrapflyError>
Cancel a schedule. Cancellation is terminal (returns no body).
Sourcepub async fn pause_schedule(&self, id: &str) -> Result<Schedule, ScrapflyError>
pub async fn pause_schedule(&self, id: &str) -> Result<Schedule, ScrapflyError>
Pause an active schedule. Idempotent on already-paused schedules.
Sourcepub async fn resume_schedule(&self, id: &str) -> Result<Schedule, ScrapflyError>
pub async fn resume_schedule(&self, id: &str) -> Result<Schedule, ScrapflyError>
Resume a paused schedule. Idempotent on already-active schedules.
Sourcepub async fn execute_schedule(
&self,
id: &str,
) -> Result<Schedule, ScrapflyError>
pub async fn execute_schedule( &self, id: &str, ) -> Result<Schedule, ScrapflyError>
Fire a schedule immediately, regardless of next_scheduled_date.