Struct elastic::client::AsyncClientBuilder
[−]
[src]
pub struct AsyncClientBuilder { /* fields omitted */ }
A builder for an asynchronous client.
Methods
impl AsyncClientBuilder
[src]
fn new() -> Self
[src]
Create a new client builder.
By default, a client constructed by this builder will:
- Send requests to
localhost:9200
- Not deserialise repsonses on a cpu pool
- Not use any authentication
- Not use TLS
fn from_params(params: RequestParams) -> Self
[src]
Create a new client builder with the given default request parameters.
fn base_url<I>(self, base_url: I) -> Self where
I: Into<String>,
[src]
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 = SyncClientBuilder::new() .base_url("https://my_es_cluster/some_path");
fn params<F>(self, builder: F) -> Self where
F: Fn(RequestParams) -> RequestParams,
[src]
F: Fn(RequestParams) -> RequestParams,
Specify default request parameters.
Examples
Require all responses use pretty-printing:
let builder = SyncClientBuilder::new() .params(|p| { p.url_param("pretty", true) });
Add an authorization header:
use elastic::http::header::Authorization; let builder = SyncClientBuilder::new() .params(|p| { p.header(Authorization("let me in".to_owned())) });
Specify a base url (prefer the base_url
method on SyncClientBuilder
instead):
let builder = SyncClientBuilder::new() .params(|p| { p.base_url("https://my_es_cluster/some_path") });
fn serde_pool<P>(self, serde_pool: P) -> Self where
P: Into<Option<CpuPool>>,
[src]
P: Into<Option<CpuPool>>,
Use the given CpuPool
for serialising and deserialising responses.
If the pool is None
then responses will be serialised and deserialised on the same thread as the io Core
.
Examples
Use a cpu pool to serialise and deserialise responses:
let pool = CpuPool::new(4); let builder = AsyncClientBuilder::new().serde_pool(pool);
fn build<TIntoHttp>(self, client: TIntoHttp) -> Result<AsyncClient, Error> where
TIntoHttp: IntoAsyncHttpClient,
[src]
TIntoHttp: IntoAsyncHttpClient,
Construct an AsyncClient
from this builder.
The build
method accepts any type that can be used to construct a http client from.
Examples
Build with an asynchronous Handle
.
This will build an AsyncClient
with a default underlying AsyncHttpClient
using the handle.
let mut core = Core::new()?; let builder = AsyncClientBuilder::new().build(&core.handle());
Build with a given AsyncHttpClient
.
let mut core = Core::new()?; let client = Client::new(&core.handle()); let builder = AsyncClientBuilder::new().build(client);