GithubHelp home page GithubHelp logo

ori155 / odata-simple-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from datavirke/odata-simple-client

0.0 0.0 0.0 31 KB

Simple client for interacting with OpenData APIs, specifically oda.ft.dk

Rust 100.00%

odata-simple-client's Introduction

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.

odata-simple-client's People

Contributors

mathiaspius avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.