The odoo-api
odoo-api is a Rust library crate that provides a user-friendly interface
to interact with the Odoo JSONRPC and ORM APIs, while preserving strong typing. It
includes both async and blocking support out of the box, and allows users to provide
their own implementations if needed.
See the Example section below for a brief example, or the client
module for more in-depth examples.
- Strong typing:
odoo-api
prioritizes the use of concrete types wherever possible, rather than relying on genericjson!{}
calls. - Async and blocking support: the library provides both async and blocking
HTTP impls via
reqwest
, and allows users to easily provide their own HTTP impl via a shim closure. - JSONRPC API support: including database management (create, duplicate, etc),
translations, and generic
execute
andexecute_kw
- ORM API support: including user-friendly APIs for the CRUD,
search_read
, security rule checking, and more - Types-only: allowing you to include this library for its types only. See Types Only below for more info
See the service
module for a full list of supported API methods.
Do you already have an HTTP library in your dependencies (e.g., reqwest
)?
The odoo-api
crate allows you to use your existing HTTP library by writing a
simple shim closure. See client::ClosureAsync
or client::ClosureBlocking
for more info.
The crate offers a types-only
feature. When enabled, the library only exposes
the API request & response types, along with Serialize
and Deserialize
impls.
The async/blocking impls (and the reqwest
dependency) are dropped when this
feature is active.
See the jsonrpc
module for information on types-only
.
Add the following to your `Cargo.toml`:
[dependencies]
odoo_api = "0.2"
Then make your requests:
use odoo_api::{OdooClient, jvec, jmap};
// build the client
let url = "https://odoo.example.com";
let mut client = OdooClient::new_reqwest_async(url)?;
// authenticate with `some-database`
let mut client = client.authenticate(
"some-database",
"admin",
"password",
).await?;
// fetch a list of users with the `execute` method
let users = client.execute(
"res.users",
"search",
jvec![
[["active", "=", true], ["login", "!=", "__system__"]]
]
).send().await?;
// fetch the login and partner_id fields from user id=1
let info = client.execute_kw(
"res.users",
"read",
jvec![[1]],
jmap!{
"fields": ["login", "partner_id"]
}
).send().await?;
// create 2 new partners with the `create` ORM method
let partners = client.create(
"res.partner",
jvec![{
"name": "Alice",
"email": "[email protected]",
"phone": "555-555-5555",
}, {
"name": "Bob",
"email": "[email protected]",
"phone": "555-555-5555",
}]
).send().await?;
// fetch a list of databases
let databases = client.db_list(false).send().await?;
// fetch server version info
let version_info = client.common_version().send().await?;