Carbone-sdk-rust
Use the Carbone Rust SDK to communicate with the Carbone API to generate documents.
Installation
[]
= "1.0.0"
Quickstart
Try the following code to render a report in 10 seconds. Just insert your API key, the template ID you want to render, and the JSON data-set as string. Get your API key on your Carbone account: https://account.carbone.io/.
use env;
use Config;
use Carbone;
use ;
use TemplateId;
use CarboneError;
use File;
use Write
async
Rust SDK API
Table of content
- SDK functions:
- Build commands
- Test commands
- Contributing
Carbone SDK Constructor
Definition
let config: Config;
Example
Example of a new SDK instance for Carbone Cloud: Get your API key on your Carbone account: https://account.carbone.io/.
// For Carbone Cloud, provide your API Access Token as first argument:
let token = "Token";
let config: Config = Default default;
let api_token = new?;
let carbone = new?;
Example of a new SDK instance for Carbone On-premise or Carbone On-AWS:
// Define the URL of your Carbone On-premise Server or AWS EC2 URL:
let config: Config = new.expect;
let carbone = new?;
Constructor to create a new instance of CarboneSDK. The access token can be pass as an argument or by the environment variable "CARBONE_TOKEN". Get your API key on your Carbone account: https://account.carbone.io/. To set a new environment variable, use the command:
Check if it is set by running:
|
Generate and Download Document
Generate a document from a local template file:
pub async ;
Arguments details:
- template_name: filename of the template.
- template_data: The content of the file in
Vec<u8>
. - json_data: A stringified JSON containing the data to populate the template.
Example
let file_name = "name_file.extention";
let file_path = format!;
let file_content = read?;
let json_data_value = String from;
let json_data = new?;
let content = match carbone.generate_report.await ;
Or, Generate a document from a template ID:
pub async async ;
Argument details:
- template_id: Template ID (Manage your templates on Carbone Studio)
- json_data: A stringified JSON containing the data to populate the template.
let template_id = new?;
let json_data = String from;
let json_data = new?;
let content = match carbone.generate_report_with_template_id.await ;
Add Template
pub async ;
Add a template as file-content Vec<u8>
and the function return the template ID as String
.
Example
let template_name = "template.odt".to_string;
let template_path = format!;
let template_data = read?;
let template_id = match carbone.upload_template.await ;
Delete Template
pub async ;
Delete a template by providing a template ID as template_id
, and it returns whether the request succeeded as a Boolean
.
Example
let template_id = new?;
let boolean = match carbone.delete_template.await ;
Generate Document Only
The generate_report function takes a template ID as String
, and the JSON data-set as JsonData
.
It return a renderId
, you can pass this renderId
at get_report for download the document.
pub async ;
Example
let template_id = new?;
let json_data = String from;
let json_data = new?;
let render_id = match carbone.render_data.await ;
Download Document Only
Definition
pub async ;
Example
let render_id = new?;
let content = match carbone.get_report.await ;
Get Template
Definition
pub async ;
Provide a template ID as String
and it returns the file as Bytes
.
Example
let template_id = new?;
let content = match carbone.download_template.await ;
Get API Status
Definition
pub async ;
The function requests the Carbone API to get the current status and version as String
.
Example
let status = match carbone.get_status.await ;
Set API Config
Definition
Set the API URL for Carbone On-premise or Carbone On-AWS.
Specify the version of the Carbone CLoud API you want to request as second argument of the constructor.
By default, all requested are made to the Carbone API version 4
.
Example
let config: Config = new.expect;
let carbone = new?;
Build commands
At the root of the SDK repository run:
In another Rust project, you can load the local build of the SDK, in the Cargo.toml:
= { = "your/local/path"}
Finally, compile your Rust project with the SDK:
Test commands
Execute unit tests:
Execute unit tests with coverage:
👤 History
The package was originaly made by Pascal Chenevas, and open-sourced the code. The Carbone.io team is now maintaining the SDK and will bring all futur evolutions.
🤝 Contributing
Contributions, issues and feature requests are welcome! Feel free to check issues page.
Show your support
Give a ⭐️ if this project helped you!