Struct elastic::client::ClientBuilder
[−]
[src]
pub struct ClientBuilder { /* fields omitted */ }
A builder for a client.
Methods
impl ClientBuilder
[src]
fn new() -> Self
Create a new client builder.
By default, a client constructed by this builder will:
- Send requests to
localhost:9200
- Not use any authentication
- Not use TLS
fn base_url<I>(self, base_url: I) -> Self where
I: Into<String>,
I: Into<String>,
Set the base url.
The url must be fully qualified.
This method is a convenient alternative to using params
to specify the base_url
.
Examples
Specify a base url for the client to send requests to. In this case, the base url is HTTPS, and not on the root path:
let builder = ClientBuilder::new() .base_url("https://my_es_cluster/some_path");
fn params<F>(self, builder: F) -> Self where
F: Fn(RequestParams) -> RequestParams,
F: Fn(RequestParams) -> RequestParams,
Specify default request parameters.
Examples
Require all responses use pretty-printing:
let builder = ClientBuilder::new() .params(|params| params.url_param("pretty", true));
Add an authorization header:
use elastic::http::header::Authorization; let builder = ClientBuilder::new() .params(|params| params.header(Authorization("let me in".to_owned())));
Specify a base url (prefer the base_url
method on ClientBuilder
instead):
let builder = ClientBuilder::new() .params(|params| params.base_url("https://my_es_cluster/some_path"));
fn http_client(self, client: HttpClient) -> Self
Use the given reqwest::Client
for sending requests.
fn build(self) -> Result<Client>
Construct a Client
from this builder.