elastic_requests
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 = for_index_ty;
assert_eq!;
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 = for_index_ty;
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:
// Use a borrowed request
do_something_with_a_request;
// Take ownership of the request
do_something_with_a_request;
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