Skip to main content

Client

Struct Client 

Source
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

Source

pub fn builder() -> ClientBuilder

Start a new ClientBuilder.

Source

pub fn api_key(&self) -> &str

Return the configured API key.

Source

pub fn host(&self) -> &str

Return the configured API host.

Source

pub fn cloud_browser_host(&self) -> &str

Return the configured Cloud Browser host.

Source

pub async fn verify_api_key(&self) -> Result<VerifyApiKeyResult, ScrapflyError>

Verify the API key by hitting /account.

Source

pub async fn account(&self) -> Result<AccountData, ScrapflyError>

Fetch account info.

Source

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.

Source

pub async fn get_monitoring_metrics( &self, opts: &MonitoringMetricsOptions, ) -> Result<Value, ScrapflyError>

Fetch aggregate monitoring metrics for the Web Scraping API.

Source

pub async fn get_monitoring_target_metrics( &self, opts: &MonitoringTargetMetricsOptions, ) -> Result<Value, ScrapflyError>

Fetch per-target monitoring metrics for the Web Scraping API.

Source

pub async fn get_screenshot_monitoring_metrics( &self, opts: &MonitoringMetricsOptions, ) -> Result<Value, ScrapflyError>

Fetch aggregate monitoring metrics for the Screenshot API.

Source

pub async fn get_screenshot_monitoring_target_metrics( &self, opts: &MonitoringTargetMetricsOptions, ) -> Result<Value, ScrapflyError>

Fetch per-target monitoring metrics for the Screenshot API.

Source

pub async fn get_extraction_monitoring_metrics( &self, opts: &MonitoringMetricsOptions, ) -> Result<Value, ScrapflyError>

Fetch aggregate monitoring metrics for the Extraction API.

Source

pub async fn get_extraction_monitoring_target_metrics( &self, opts: &MonitoringTargetMetricsOptions, ) -> Result<Value, ScrapflyError>

Fetch per-target monitoring metrics for the Extraction API.

Source

pub async fn get_crawler_monitoring_metrics( &self, opts: &MonitoringMetricsOptions, ) -> Result<Value, ScrapflyError>

Fetch aggregate monitoring metrics for the Crawler API.

Source

pub async fn get_crawler_monitoring_target_metrics( &self, opts: &MonitoringTargetMetricsOptions, ) -> Result<Value, ScrapflyError>

Fetch per-target monitoring metrics for the Crawler API.

Source

pub async fn get_browser_monitoring_metrics( &self, opts: &CloudBrowserMonitoringOptions, ) -> Result<Value, ScrapflyError>

Fetch aggregate monitoring metrics for the Cloud Browser API.

Source

pub async fn get_browser_monitoring_timeseries( &self, opts: &CloudBrowserMonitoringOptions, ) -> Result<Value, ScrapflyError>

Fetch monitoring time-series for the Cloud Browser API.

Source

pub async fn scrape( &self, config: &ScrapeConfig, ) -> Result<ScrapeResult, ScrapflyError>

Scrape a URL.

Source

pub fn concurrent_scrape<'a, I>( &'a self, configs: I, concurrency_limit: usize, ) -> impl Stream<Item = Result<ScrapeResult, ScrapflyError>> + 'a
where I: IntoIterator<Item = ScrapeConfig> + 'a, <I as IntoIterator>::IntoIter: 'a,

Concurrent-scrape stream. Emits results in completion order.

Source

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.

Source

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.).

Source

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.

Source

pub async fn screenshot( &self, config: &ScreenshotConfig, ) -> Result<ScreenshotResult, ScrapflyError>

Screenshot a URL.

Source

pub async fn extract( &self, config: &ExtractionConfig, ) -> Result<ExtractionResult, ScrapflyError>

Run AI extraction on a document.

Source

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 and remote_url_list crawls.
  • multipart/form-data — a config JSON part and a urls text part (one URL per line). Used only when the caller provides an in-memory url_list, so the URLs are uploaded as a streamed file payload instead of inlined into the JSON body.
Source

pub async fn crawl_status( &self, uuid: &str, ) -> Result<CrawlerStatus, ScrapflyError>

Fetch crawler status.

Source

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).

Source

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.

Source

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.

Source

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).

Source

pub async fn crawl_cancel(&self, uuid: &str) -> Result<(), ScrapflyError>

Cancel a crawler job.

Source

pub async fn crawl_artifact( &self, uuid: &str, artifact_type: CrawlerArtifactType, ) -> Result<CrawlerArtifact, ScrapflyError>

Download a crawler artifact (WARC or HAR).

Source§

impl Client

Source

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

Source

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.

Source

pub async fn cloud_browser_unblock( &self, config: &UnblockConfig, ) -> Result<UnblockResult, ScrapflyError>

Call POST /unblock to bypass anti-bot protection.

Source

pub async fn cloud_browser_extension_list(&self) -> Result<Value, ScrapflyError>

List browser extensions for the account.

Source

pub async fn cloud_browser_extension_get( &self, extension_id: &str, ) -> Result<Value, ScrapflyError>

Get details of a specific browser extension.

Source

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).

Source

pub async fn cloud_browser_extension_delete( &self, extension_id: &str, ) -> Result<Value, ScrapflyError>

Delete a browser extension by ID.

Source

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.

Source

pub async fn cloud_browser_vault_list(&self) -> Result<Value, ScrapflyError>

List all credential vaults for the account.

Source

pub async fn cloud_browser_vault_get( &self, vault_id: &str, ) -> Result<Value, ScrapflyError>

Get vault metadata. Does NOT include any secret material.

Source

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.

Source

pub async fn cloud_browser_vault_delete( &self, vault_id: &str, ) -> Result<Value, ScrapflyError>

Delete a vault by id (cascades to all items).

Source

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.

Source

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.

Source

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"}
}
Source

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.

Source

pub async fn cloud_browser_vault_item_delete( &self, vault_id: &str, item_id: &str, ) -> Result<Value, ScrapflyError>

Delete a single vault item.

Source

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.

Source

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.

Source

pub async fn cloud_browser_session_stop( &self, session_id: &str, ) -> Result<(), ScrapflyError>

Terminate a Cloud Browser session.

Source

pub async fn cloud_browser_sessions(&self) -> Result<Value, ScrapflyError>

List all running Cloud Browser sessions.

Source

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

Source

pub async fn create_scrape_schedule( &self, scrape_config: HashMap<String, Value>, request: &CreateScheduleRequest, ) -> Result<Schedule, ScrapflyError>

Create a Web Scraping API schedule.

Source

pub async fn create_screenshot_schedule( &self, screenshot_config: HashMap<String, Value>, request: &CreateScheduleRequest, ) -> Result<Schedule, ScrapflyError>

Create a Screenshot API schedule.

Source

pub async fn create_crawler_schedule( &self, crawler_config: HashMap<String, Value>, request: &CreateScheduleRequest, ) -> Result<Schedule, ScrapflyError>

Create a Crawler API schedule.

Source

pub async fn get_schedule(&self, id: &str) -> Result<Schedule, ScrapflyError>

Return a schedule by id (works across all kinds).

Source

pub async fn list_schedules( &self, opts: Option<&ListSchedulesOptions>, ) -> Result<Vec<Schedule>, ScrapflyError>

List every schedule on the account, optionally filtered by kind/status.

Source

pub async fn list_scrape_schedules( &self, status: Option<&str>, ) -> Result<Vec<Schedule>, ScrapflyError>

List scrape schedules, optionally filtered by status.

Source

pub async fn list_screenshot_schedules( &self, status: Option<&str>, ) -> Result<Vec<Schedule>, ScrapflyError>

List screenshot schedules, optionally filtered by status.

Source

pub async fn list_crawler_schedules( &self, status: Option<&str>, ) -> Result<Vec<Schedule>, ScrapflyError>

List crawler schedules, optionally filtered by status.

Source

pub async fn update_schedule( &self, id: &str, request: &UpdateScheduleRequest, ) -> Result<Schedule, ScrapflyError>

Patch an active schedule. Only fields set in request change.

Source

pub async fn cancel_schedule(&self, id: &str) -> Result<(), ScrapflyError>

Cancel a schedule. Cancellation is terminal (returns no body).

Source

pub async fn pause_schedule(&self, id: &str) -> Result<Schedule, ScrapflyError>

Pause an active schedule. Idempotent on already-paused schedules.

Source

pub async fn resume_schedule(&self, id: &str) -> Result<Schedule, ScrapflyError>

Resume a paused schedule. Idempotent on already-active schedules.

Source

pub async fn execute_schedule( &self, id: &str, ) -> Result<Schedule, ScrapflyError>

Fire a schedule immediately, regardless of next_scheduled_date.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T