elastic_requests

Code generated request types for the Elasticsearch REST API

25 releases

0.21.0-pre.1 Feb 10, 2019
0.20.10 May 7, 2018
0.20.9 Feb 6, 2018
0.20.8 Dec 17, 2017
0.1.4 Dec 31, 2016

#39 in HTTP client

Download history 307/week @ 2018-10-28 308/week @ 2018-11-04 435/week @ 2018-11-11 212/week @ 2018-11-18 336/week @ 2018-11-25 349/week @ 2018-12-02 223/week @ 2018-12-09 135/week @ 2018-12-16 90/week @ 2018-12-23 43/week @ 2018-12-30 194/week @ 2019-01-06 159/week @ 2019-01-13 36/week @ 2019-01-20 161/week @ 2019-01-27 100/week @ 2019-02-03

811 downloads per month
Used in 3 crates (1 directly)

MIT/Apache

259KB
7K SLoC

elastic_requests Latest Version

elastic_requests is a strongly-typed, code-generated implementation of the Elasticsearch REST API for Rust.

This library doesn't provide HTTP transport directly, it's used by elastic and elastic_reqwest for that.

The goal is to be zero-allocation where possible, so request types are just wrappers around potentially owned data. A structure is generated for each REST endpoint, that generate url paths from the given parameters.

Example

Add elastic_requests to your Cargo.toml:

[dependencies]
elastic_requests = "*"

And reference it in your crate root:

extern crate elastic_requests as requests;

There's a request type for each REST API endpoint with constructor functions for each valid set of parameters:

let req = requests::SearchRequest::for_index_ty(
	"myindex", "mytype", 
	json_str!({
		query: { 
			match_all: {}
		}
	})
);

assert_eq!("/myindex/mytype/_search", *req.url);

Parameters can be supplied as owned or borrowed strings and the body as an owned or borrowed byte array:

let index_suffix = get_a_suffix();

let req = requests::SimpleSearchRequest::for_index_ty(
	format!("index-{}", index_suffix), "mytype"
);

There's also a more general HttpRequest structure that represents a typical request. All request types implement Into<HttpRequest> for owned or borrowed references, so you can work with an arbitrary request through this type bound:

fn do_something_with_a_request<'a, I: Into<HttpRequest<'a>>>(req: I) {}

// Use a borrowed request
do_something_with_a_request(&req);

// Take ownership of the request
do_something_with_a_request(req);

HttpRequest<'static> implements Send so it can be shared across threads.

Codegen

The types in this library are generated from the Elasticsearch REST API spec. This can be run from the codegen directory:

$ cd requests_codegen
$ cargo run > ../requests/src/genned.rs

Dependencies