datapress_client/lib.rs
1//! # datapress-client
2//!
3//! Async + blocking Rust client for a running [DataPress] dataset server.
4//!
5//! It wraps the JSON and Arrow IPC HTTP endpoints so you don't have to
6//! hand-roll request bodies and response decoding. The crate is
7//! deliberately lightweight: only `reqwest` + `serde` by default, with
8//! Arrow IPC decoding behind the (default-on) `arrow` feature and a
9//! synchronous client behind the `blocking` feature.
10//!
11//! ## Async
12//!
13//! ```no_run
14//! # async fn run() -> datapress_client::Result<()> {
15//! use datapress_client::{Client, QueryRequest, Predicate};
16//!
17//! let client = Client::new("http://127.0.0.1:8000")?;
18//! let names = client.datasets().await?;
19//!
20//! let req = QueryRequest::builder()
21//! .columns(["State", "Severity"])
22//! .predicate(Predicate::new("Severity", "gte", 3))
23//! .page_size(10_000)
24//! .build();
25//! let resp = client.query_json("accidents", &req).await?;
26//! println!("{} rows", resp.data.len());
27//! # Ok(())
28//! # }
29//! ```
30//!
31//! ## Blocking (feature `blocking`)
32//!
33//! ```no_run
34//! # #[cfg(feature = "blocking")]
35//! # fn run() -> datapress_client::Result<()> {
36//! use datapress_client::blocking::Client;
37//!
38//! let client = Client::new("http://127.0.0.1:8000")?;
39//! let count = client.count("accidents", &[])?;
40//! println!("{count} rows");
41//! # Ok(())
42//! # }
43//! ```
44//!
45//! [DataPress]: https://github.com/jeroenflvr/datapress
46
47mod client;
48mod error;
49mod models;
50
51#[cfg(feature = "blocking")]
52pub mod blocking;
53
54pub use client::{Client, ClientBuilder};
55pub use error::{ClientError, Result};
56pub use models::{
57 Aggregation, OrderBy, Predicate, QueryRequest, QueryRequestBuilder, QueryResponse, SqlRequest,
58 SqlResponse,
59};
60
61#[cfg(feature = "arrow")]
62pub use client::decode_ipc_stream;