Expand description
The Boomack API Client library.
§Overview
§Configuration
Module: boomack::client::config
The configuration contains the server URL, the API authorization token, and other parameters for the HTTP requests.
- The
Configstruct with methods for loading configuration values from different sources
§JSON
Module: boomack::client::json
JSON specific functions are required for the dynamic or extensible request parts, like e. g. display options.
- The
JsonMaptype to hold the JSON data - Conversion of your structures into a JSON map with
to_json_map
(Your structure must implement serde serialization) - Setter for manipulation
- Pretty printing with
pprint_json
§Request Building
Module: boomack::client::api::ClientRequest
In order to send a request to the HTTP API you need to first build a request structure. Every group of request has its own module with functions to create a request. Usually a parameters structure is involved to hold some or all information for the request.
- Display Request
boomack::client::display - Evaluation Request
boomack::client::eval - Panel Management
boomack::client::panels - Preset Management
boomack::client::presets - Media Type Management
boomack::client::types - Action Management
boomack::client::actions - Clearing Request
- Export Request
§Sending Request
Module: boomack::client::api
After a request was built, it is send to the server. There are two alternative functions available.
§Example
use boomack::client::config::Config;
use boomack::client::json::*;
use boomack::client::display::{ DisplayParameters, display_text_request };
use boomack::client::api::{ ClientRequest, send_request };
fn build_config() -> Config {
let mut cfg = Config::new();
// you can use different sources to set up the configuration
// start with the sources having the highest priority
// then fill gaps left from sources with lower priority
// explicit configuration values, could come from command line arguments
cfg.client.format = Some(String::from("text/plain"));
// usually environment variables are next in line
cfg.fill_gaps_with(&Config::from_env());
// load one or more specific configuration file
//let config_files = vec![String::from("my-config-file.yaml")];
//cfg.load_unknown_config_files(&config_files);
// load the default config files from user profile and current working directory:
// - boomack[.json|.yaml|.yml] from current working directory
// - .boomack[.json|.yaml|.yml] from user profile
// - boomack-server[.json|.yaml|.yml] from current working directory
// - .boomack-server[.json|.yaml|.yml] from user profile
cfg.load_known_config_files();
// and at last, load the default media type mappings
cfg.load_default_media_types();
return cfg;
}
fn prepare_request() -> ClientRequest {
// prepare the display options
let mut display_options = JsonMap::new();
set_json_str_value(&mut display_options, "background", "#AAFFCC44");
set_json_bool_value(&mut display_options, "debug", false);
// prepare display parameters with the display options
let display_params = DisplayParameters {
panel: Some("default"),
slot: None,
content_type: Some("text/markdown"),
title: Some("Example"),
presets: Vec::new(),
options: display_options,
};
// create the request with some text content
let markdown = r##"
Hello World!
This is an example showing...
* Request Configuration
* Display Options
* Display Parameters
* Sending the Request
"##;
display_text_request(&display_params, markdown)
}
fn main() {
// first prepare the configuration for HTTP requests
let cfg = build_config();
// then build the client request
let mut request = prepare_request();
// set the accepted response format from the configuration
request.set_header("Accept", cfg.client.get_format());
// send the request
let result = send_request(&cfg, &request);
// handle the result
match result {
Ok(response) => {
println!("STATUS: [{}] {}", response.status(), response.status_text());
if response.status() != 204 {
print!("RESPONSE:\n{}\n", response.into_string().unwrap());
}
},
Err(err) => {
println!("ERROR: {}", err.to_string());
},
};
}Modules§
- actions
- Functions to create
ClientRequestinstances for managing Boomack actions. - api
- Common structures and functions for all kinds of requests to the HTTP API of Boomack
- config
- Structures and function for loading and merging the configuration for the HTTP client
- display
- Structures and functions to create
ClientRequestinstances for making display requests - eval
- Structures and functions to create
ClientRequestinstances for making evaluation requests - json
- Helpers for handling dynamic or extensible data structures and converting them from and into JSON
- panels
- Structures and functions to create
ClientRequestinstances for managing panels - presets
- Functions to create
ClientRequestinstances for managing presets - slots
- Structures and functions to create
ClientRequestinstances for managing slots - types
- Functions to create
ClientRequestinstances for managing media types