Trait InfluxLineClientWrapper

Source
pub trait InfluxLineClientWrapper {
    type RequestBuilderType;

    // Required method
    fn line_protocol(
        &self,
        base_url: &Url,
        database: &str,
        lines: &[Line],
    ) -> Result<Self::RequestBuilderType, ClientError>;
}
Expand description

A trait to obtain a prepared Influx Line Protocol request builder from Reqwest clients.

This trait is used to attach a line_protocol() function to reqwest::Client.

// Bring into scope the trait implementation
use rinfluxdb_lineprotocol::r#async::InfluxLineClientWrapper;

// Create Reqwest client
let client = reqwest::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).await?;

Required Associated Types§

Source

type RequestBuilderType

The type of the resulting request builder

This type is a parameter so the trait can be implemented for reqwest::Client returning reqwest::RequestBuilder, and for reqwest::Client returning reqwest::RequestBuilder.

Required Methods§

Source

fn line_protocol( &self, base_url: &Url, database: &str, lines: &[Line], ) -> Result<Self::RequestBuilderType, ClientError>

Create an Influx Line Protocol request builder

The request will point to the InfluxDB instance available at base_url. In particular, it will send a POST request to base_url + "/query".

Implementations on Foreign Types§

Source§

impl InfluxLineClientWrapper for Client

Implementors§