#json #template #reports #data #render #docx #carbone

carbone-sdk-rust

Generate PDF, DOCX, XLSX, ..., HTML reports from templates and JSON data with Carbone API

1 unstable release

0.1.0 Oct 1, 2023

#5 in #docx

Apache-2.0

155KB
601 lines

License Rust unstable

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_rs::config::Config;
use carbone_sdk_rs::carbone::Carbone;
use carbone_sdk_rs::types::{ApiJsonToken, JsonData};
use carbone_sdk_rs::template::TemplateId;
 
use carbone_sdk_rs::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.

Contributor

Author: https://github.com/pascal-chenevas

Dependencies

~13–30MB
~542K SLoC