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