Struct elastic::client::responses::AsyncResponseBuilder
[−]
[src]
pub struct AsyncResponseBuilder { /* fields omitted */ }
A builder for a response.
This structure wraps the completed HTTP response but gives you options for converting it into a concrete type.
You can also Read
directly from the response body.
Methods
impl AsyncResponseBuilder
[src]
fn status(&self) -> u16
[src]
Get the HTTP status for the response.
fn into_raw(self) -> AsyncHttpResponse
[src]
Get the response body from JSON.
Convert the builder into a raw HTTP response that implements Read
.
fn into_response<T>(self) -> IntoResponse<T> where
T: IsOk + DeserializeOwned + Send + 'static,
[src]
T: IsOk + DeserializeOwned + Send + 'static,
Parse an API response type from the HTTP body.
The deserialisation may occur on a background thread.
This will consume the AsyncResponseBuilder
and return a concrete response type or an error.
The response is parsed according to the IsOk
implementation for T
that will inspect the response and either return an Ok(T)
or an Err(ApiError)
.
Examples
Get a strongly typed SearchResponse
:
let future = client.request(SimpleSearchRequest::for_index_ty("myindex", "mytype")) .send() .and_then(|response| response.into_response::<SearchResponse<MyType>>()); future.and_then(|response| { // Iterate through the hits (of type `MyType`) for hit in response.hits() { println!("{:?}", hit); } Ok(()) });
You can also read a response as a serde_json::Value
, which will be Ok(Value)
if the HTTP status code is Ok
or Err(ApiError)
otherwise:
let future = client.request(SimpleSearchRequest::for_index_ty("myindex", "mytype")) .send() .and_then(|response| response.into_response::<Value>());