odata-simple-client

Crates.ioodata-simple-client
lib.rsodata-simple-client
version0.2.6
sourcesrc
created_at2021-11-13 20:19:01.159938
updated_at2023-01-14 14:03:12.664416
descriptionSimplified OpenData API Client
homepage
repositoryhttps://github.com/Datavirke/odata-simple-client
max_upload_size
id481518
size33,129
Mathias Pius (MathiasPius)

documentation

README

odata-simple-client

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.

Commit count: 31

cargo fmt