pub trait InfluxLineResponseWrapper {
// Required method
fn process_line_protocol_response(self) -> Result<(), ClientError>;
}
Expand description
A trait to parse a list of dataframes from Reqwest responses.
This trait is used to attach a dataframes()
function to reqwest::blocking::Response
.
use rinfluxdb_lineprotocol::blocking::InfluxLineClientWrapper;
// Bring into scope the trait implementation
use rinfluxdb_lineprotocol::blocking::InfluxLineResponseWrapper;
// Create Reqwest client
let client = reqwest::blocking::Client::new();
// Set database name
let database = "database";
// Create data
let lines = vec![
LineBuilder::new("measurement")
.insert_field("field", 42.0)
.build(),
LineBuilder::new("measurement")
.insert_field("field", 43.0)
.insert_tag("tag", "value")
.build(),
];
// Create Influx Line Protocol request
let base_url = Url::parse("https://example.com")?;
let mut builder = client
// (this is a function added by the trait above)
.line_protocol(&base_url, &database, &lines)?;
// This is a regular Reqwest builder, and can be customized as usual
if let Some((username, password)) = Some(("username", "password")) {
builder = builder.basic_auth(username, Some(password));
}
// Create a request from the builder
let request = builder.build()?;
// Execute the request through Reqwest and obtain a response
let response = client.execute(request)?;
// Process the response.
response.process_line_protocol_response()?;
Required Methods§
Sourcefn process_line_protocol_response(self) -> Result<(), ClientError>
fn process_line_protocol_response(self) -> Result<(), ClientError>
Process the response, parsing potential errors