odoo-api

github crates.io docs.rs docs.rs

Type-safe and full-coverage implementation of the Odoo API. Supports async, blocking, and bring-your-own-requests

NOTE: This crate is still under active development, and the public API isn't stable yet.

Features


Get Started

First, decide how you want to use this library: - Using the built-in async support via reqwest - Using the built-in blocking support via reqwest - Use this library for its types only, and bring your own requests library

Async with reqwest

Documentation

```toml

Cargo.toml

[dependencies] odoo_api = { version = "0.1", features = ["async"] } ```

```rust // pull in API functions from the 'asynch' module use odooapi::asynch::{object}; use serdejson::json;

// fetch a list of all usernames let users = object::executekw( "https://demo.odoo.com/jsonrpc", "my-database", 1, "password1", "res.users", "searchread", json!([]), json!({ "domain": [[true, "=", true]], "fields": ["login"] }), ).await?.data; ```

Blocking with reqwest

Documentation

```toml

Cargo.toml

[dependencies] odoo_api = { version = "0.1", features = ["blocking"] } ```

```rust // pull in API functions from the 'blocking' module use odooapi::blocking::{object}; use serdejson::json;

// fetch a list of all usernames let users = object::executekw( "https://demo.odoo.com/jsonrpc", "my-database", 1, "password1", "res.users", "searchread", json!([]), json!({ "domain": [[true, "=", true]], "fields": ["login"] }), )?.data; println!("Users: {:?}", users); ```

Bring your Own Requests

See the link below for more info on building the request types, converting to JSON String or serde_json::Value, and parsing the response.

Documentation

```toml

Cargo.toml

[dependencies] odoo_api = { version = "0.1", features = [] } ```

```rust // pull in API functions from the 'types' module use odooapi::types::{object}; use serdejson::json;

// build the request object let req = object::executekw( "my-database", 1, "password1", "res.users", "searchread", json!([]), json!({ "domain": [[true, "=", true]], "fields": ["login"] }), )?;

// convert into a JSON String .. let reqdata = req.tojsonstring()?; // .. or a serde_json::Value let reqdata = req.tojsonvalue()?; // .. or, if your request library accepts types that implement [serde::Serialize], // you can pass the struct directly

// fetch the response, e.g.: // let respdata = request.post(url).jsonbody(&reqdata).send()?.tojson()?;

// finally, parse the response JSON using the Response objects' tryfrom impl let resp: object::ExecuteKwResponse = respdata.try_into()?;

println!("Users: {:#?}", resp.data); ```


Optional Features