odoo-api
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
-
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 implementSerialize
, functions to convert intoserde_json::Value
, and functions to dump the request out as a plain JSONString
, 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.
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
## Cargo.toml
[]
= { = "0.1", = ["async"] }
// pull in API functions from the 'asynch' module
use ;
use json;
// fetch a list of all usernames
let users = execute_kw.await?.data;
Blocking with reqwest
## Cargo.toml
[]
= { = "0.1", = ["blocking"] }
// pull in API functions from the 'blocking' module
use ;
use json;
// fetch a list of all usernames
let users = execute_kw?.data;
println!;
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.
## Cargo.toml
[]
= { = "0.1", = [] }
// pull in API functions from the 'types' module
use ;
use json;
// build the request object
let req = execute_kw?;
// convert into a JSON `String` ..
let req_data = req.to_json_string?;
// .. or a `serde_json::Value`
let req_data = req.to_json_value?;
// .. or, if your request library accepts types that implement [`serde::Serialize`],
// you can pass the struct directly
// fetch the response, e.g.:
// let resp_data = request.post(url).json_body(&req_data).send()?.to_json()?;
// finally, parse the response JSON using the Response objects' try_from impl
let resp: ExecuteKwResponse = resp_data.try_into?;
println!;
Optional Features
- async - Enable async HTTP request support via [
reqwest
] - blocking - Enable blocking HTTP request support via [
reqwest
]