odoo_api/lib.rs
1//! # odoo_api
2//! The `odoo_api` crate provides a type-safe and full-coverage implementation
3//! of the Odoo JSON-RPC API, including ORM and Web methods. It supports sessioning,
4//! multi-database, async and blocking via [`reqwest`], and bring-your-own requests.
5//!
6//! ## API Methods
7//!
8//! For a full list of supported API methods, see [`service`].
9//!
10//! ## Bring your own requests
11//!
12//! By default, `odoo_api` uses [`reqwest`] as its HTTP implementation. It is also
13//! possible to provide your own HTTP implementation (see [`OdooClient`] for more info).
14//!
15//! ## Example
16//!
17//! To use the default [`reqwest`] implementation, add this to your `Cargo.toml`:
18//!
19//! ```toml
20//! [dependencies]
21//! odoo_api = "0.2"
22//! ```
23//!
24//! Then make your requests:
25//! ```no_run
26//! # #[cfg(not(feature = "types-only"))]
27//! use odoo_api::{OdooClient, jvec, jmap};
28//!
29//! # #[cfg(not(feature = "types-only"))]
30//! # async fn test() -> odoo_api::client::Result<()> {
31//! // build the client and authenticate
32//! let url = "https://demo.odoo.com";
33//! let mut client = OdooClient::new_reqwest_async(url)?
34//! .authenticate(
35//! "some-database",
36//! "admin",
37//! "password",
38//! ).await?;
39//!
40//! // fetch a list of users
41//! let users = client.execute(
42//! "res.users",
43//! "search",
44//! jvec![]
45//! ).send().await?;
46//!
47//! // fetch the login and partner_id fields from user id=1
48//! let info = client.execute_kw(
49//! "res.users",
50//! "read",
51//! jvec![[1]],
52//! jmap!{
53//! "fields": ["login", "partner_id"]
54//! }
55//! ).send().await?;
56//!
57//! // fetch a list of databases
58//! let databases = client.db_list(false).send().await?;
59//!
60//! // fetch server version info
61//! let version_info = client.common_version().send().await?;
62//! # Ok(())
63//! # }
64//! ```
65
66// The `types-only` feature implies that the `client` module isn't included, so
67// `async` and `blocking` have no effect
68#[cfg(all(feature = "types-only", any(feature = "async", feature = "blocking")))]
69std::compile_error!(
70 "The `types-only` feature is mutually exclusive with the `async` and `blocking` \
71 features. Please disable the `async` and `blocking` by adding `default-features = false` \
72 to your Cargo.toml"
73);
74
75pub mod service;
76
77#[macro_use]
78mod macros;
79
80#[cfg(not(feature = "types-only"))]
81pub mod client;
82
83#[cfg(not(feature = "types-only"))]
84pub use client::{AsyncClosureReturn, BlockingClosureReturn, OdooClient};
85
86pub mod jsonrpc;
87pub use jsonrpc::OdooId;