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.
Full Coverage - All JSON-RPC endpoints are covered, including the
various database-management methods (create_database
, dump
, list
, etc).
Support for some common ORM methods is also included (read
, search_read
, create
, etc).
Flexible - Use the built-in async/blocking HTTP request support
(via reqwest
), or simply use this crate for its types and use your own
requests library. The API request and response types all implement Serialize
,
functions to convert into serde_json::Value
, and functions to dump the
request out as a plain JSON String
, so almost any requests library will work.
Type-Safe - The odoo-api
crate implements types for as much of the
Odoo API as possible, right up to the positional & keyword arguments for
some ORM methods.
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
reqwest
```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; ```
reqwest
```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); ```
See the link below for more info on building the request types, converting
to JSON String
or serde_json::Value
, and parsing the response.
```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); ```
reqwest
]reqwest
]