Carbone-sdk-rust
Carbone-sdk-rust is a Library that supplies functionalities to communicate with the Carbone API.
State of development
This Library is in the early stage of active development and doesn't reach the status of a stable release. Therefore it can not be used in a production environment.
Process to render a new report
sequenceDiagram
Client->>Carbone API: send a template file to /template
Carbone API-->>Client: send a template_id
Client->>Carbone API: send json data to be rendered to /render/{template_id}
Carbone API-->>Client: send a render_id
Carbone API-->>Client: get the rendered report from /render/{render_id}
Installation
TODO
Render a new report
Using an existing Template
use std::env;
use carbone_sdk_rust::config::Config;
use carbone_sdk_rust::carbone::Carbone;
use carbone_sdk_rust::types::{ApiJsonToken, JsonData};
use carbone_sdk_rust::template::TemplateId;
use carbone_sdk_rust::errors::CarboneError;
#[tokio::main]
async fn main() -> Result<(), CarboneError> {
let token = match env::var("CARBONE_TOKEN") {
Ok(v) => v,
Err(e) => panic!("{}", e.to_string())
};
let config: Config = Default::default();
let api_token = ApiJsonToken::new(token)?;
let json_data_value = String::from(r#"
"data" : {
"firstname" : "John",
"lastname" : "Wick"
},
"convertTo" : "odt"
"#);
let json_data = JsonData::new(json_data_value)?;
let template_id = TemplateId::new("0545253258577a632a99065f0572720225f5165cc43db9515e9cef0e17b40114".to_string())?;
let carbone = Carbone::new(&config, &api_token)?;
let _report_content = carbone.generate_report_with_template_id(template_id, json_data).await?;
Ok(())
}
References
Carbone.io a report generator.
Carbone CLI App a simple CLI App to create reports.