apify_client/lib.rs
1//! # apify-client
2//!
3//! **Official, but experimental — AI-generated and AI-maintained.** This is an official Apify
4//! client, but it is experimental: it is generated and maintained by AI. Review the code before
5//! relying on it in production and report issues on the repository.
6//!
7//! An idiomatic Rust client for the [Apify API](https://docs.apify.com/api/v2).
8//!
9//! It provides a resource-oriented interface that mirrors the official
10//! [JavaScript](https://github.com/apify/apify-client-js) and Python clients: start from
11//! an [`ApifyClient`], then drill down into resources (Actors, runs, datasets, key-value
12//! stores, request queues, tasks, schedules, webhooks, the store, users and logs).
13//!
14//! ## Quick start
15//!
16//! ```no_run
17//! use apify_client::ApifyClient;
18//!
19//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
20//! let client = ApifyClient::new("my-api-token");
21//!
22//! // Start an Actor and wait for it to finish.
23//! let run = client
24//! .actor("apify/hello-world")
25//! .call::<serde_json::Value>(None, Default::default(), None)
26//! .await?;
27//!
28//! // Read items from the run's default dataset.
29//! if let Some(dataset_id) = &run.default_dataset_id {
30//! let items = client
31//! .dataset(dataset_id)
32//! .list_items::<serde_json::Value>(Default::default())
33//! .await?;
34//! println!("Got {} items", items.items.len());
35//! }
36//! # Ok(())
37//! # }
38//! ```
39//!
40//! ## Architecture
41//!
42//! - **Public interface**: [`ApifyClient`] and the resource clients in [`clients`].
43//! - **Replaceable transport**: the [`http_client::HttpBackend`] trait, with a default
44//! [`http_client::ReqwestBackend`]. Swap it via
45//! [`ApifyClientBuilder::http_backend`].
46//! - **Cross-cutting behaviour** (auth, `User-Agent`, retries with exponential backoff,
47//! timeouts) lives in [`http_client::HttpClient`] and is applied to every request.
48
49#![warn(missing_docs)]
50
51mod client;
52pub mod clients;
53pub mod common;
54pub mod error;
55pub mod http_client;
56pub mod models;
57mod version;
58
59pub use client::{ApifyClient, ApifyClientBuilder};
60pub use common::{ListOptions, PaginationList, QueryParams, StorageListOptions};
61pub use error::{ApiError, ApifyClientError, ApifyClientResult};
62pub use http_client::RequestCompression;
63pub use version::{API_SPEC_VERSION, CLIENT_VERSION};
64
65// Re-export the most commonly used option/parameter types for ergonomic access.
66pub use clients::actor::{ActorBuildOptions, ActorStartOptions};
67pub use clients::actor_collection::ActorListOptions;
68pub use clients::dataset::{DatasetDownloadOptions, DatasetListItemsOptions, DownloadItemsFormat};
69pub use clients::key_value_store::{GetRecordOptions, KeyValueStoreKeysIterator, ListKeysOptions};
70pub use clients::log::LogOptions;
71pub use clients::pagination::ListIterator;
72pub use clients::request_queue::{ListRequestsOptions, RequestQueueRequestsIterator};
73pub use clients::run::{
74 LastRunOptions, RunChargeOptions, RunMetamorphOptions, RunResurrectOptions,
75};
76pub use clients::run_collection::RunListOptions;
77pub use clients::store_collection::{StoreActorIterator, StoreListOptions};
78
79// Compile-test the code snippets in the README and the external `docs/` pages so every
80// in-documentation code snippet stays valid and runnable. Pulling each Markdown file in as
81// a doctest source means `cargo test --doc` (the `Test examples` CI step) compiles every
82// `rust` fenced block; `no_run` blocks are compiled but not executed, runnable blocks run.
83#[doc = include_str!("../README.md")]
84#[cfg(doctest)]
85struct ReadmeDoctests;
86
87#[doc = include_str!("../docs/README.md")]
88#[cfg(doctest)]
89struct DocsReadmeDoctests;
90
91#[doc = include_str!("../docs/actors.md")]
92#[cfg(doctest)]
93struct DocsActorsDoctests;
94
95#[doc = include_str!("../docs/misc.md")]
96#[cfg(doctest)]
97struct DocsMiscDoctests;
98
99#[doc = include_str!("../docs/storages.md")]
100#[cfg(doctest)]
101struct DocsStoragesDoctests;
102
103#[doc = include_str!("../docs/runs.md")]
104#[cfg(doctest)]
105struct DocsRunsDoctests;
106
107#[doc = include_str!("../docs/builds.md")]
108#[cfg(doctest)]
109struct DocsBuildsDoctests;