Crate odata_simple_client
source ·Expand description
This crate provides a Rust-interface to an OData 3.0 API over HTTP(S)
To get started, construct a DataSource
and then create either a ListRequest
or GetRequest
and
fetch
/fetch_paged
it using your DataSource
Here’s a complete example which fetches a single Dokument
from the Danish Parliament’s OData API:
use hyper::{Client, client::HttpConnector};
use hyper_openssl::{HttpsConnector};
use odata_simple_client::{DataSource, GetRequest};
use serde::Deserialize;
#[derive(Deserialize)]
struct Dokument {
titel: String,
}
// Construct a Hyper client for communicating over HTTPS
let client: Client<HttpsConnector<HttpConnector>> =
Client::builder().build(HttpsConnector::<HttpConnector>::new().unwrap());
// Set up our DataSource. The API is reachable on https://oda.ft.dk/api/
let datasource = DataSource::new(client, "oda.ft.dk", Some(String::from("/api"))).unwrap();
// The tokio_test::block_on call is just to make this example work in a rustdoc example.
// Normally you would just write the enclosed code in an async function.
tokio_test::block_on(async {
let dokument: Dokument = datasource.fetch(
GetRequest::new("Dokument", 24)
).await.unwrap();
assert_eq!(dokument.titel, "Grund- og nærhedsnotat vedr. sanktioner på toldområdet");
});
The example above has requirements on a number of crates. See the Cargo.toml
-file for a list.
Structs
Represents a target OData API.
Request a single resource by ID
Request a list of resources.
Wraps lists of Resources returned by the API. Used for deserializing ListRequest responses.
Enums
Used by
ListRequest::filter
to apply conditional filtering to the returned results.Specifies direction in which the returned results are listed. Use
ListRequest::order_by
to change it.
If nothing else is specified, it defaults to Direction::Ascending
Generalized Error type encompassing all the possible errors that can be generated by this crate.
Format of the returned API data.
DataSource::fetch_paged
forces Format::Json
.Used by
ListRequest::inline_count
to show number of results left in a query, before all pages have been read.Traits
Umbrella trait covering all the traits required of a
Client
for a DataSource
to work.