🚍 Singapore LTA Datamall Rust async first client. lta-rs is used to interact with the lta-datamall
```toml [dependencies]
lta = { version = "0.5.0" } ```
You can get your API key from here
```rust use lta::{LTAResult, LTAClient, Client, Traffic, TrafficRequests};
async fn main() -> LTAResult<()> { let apikey = std::env::var("APIKEY").expect("APIKEY not found!"); let client = LTAClient::withapikey(apikey)?; let erprates = Traffic::geterprates(&client, None).await?; println!("{:?}", erprates); Ok(()) } ```
Getting bus timings
```rust use lta::{LTAResult, LTAClient, Client, Bus, BusRequests};
fn getbusarrival() -> LTAResult<()> { let apikey = std::env::var("APIKEY").expect("APIKEY not found!"); let client = LTAClient::withapikey(apikey); let arrivals = Bus::get_arrival(&client, 83139, None)?; println!("{:?}", arrivals); Ok(()) } ```
Getting other data
``rust
// All the APIs in this library are designed to be used like this
//
lta::RequestType::getsomething`
// All of them return lta::utils::LTAResult
async fn busservices() -> LTAResult<()> { let apikey = std::env::var("APIKEY").expect("APIKEY not found!"); let client = LTAClient::withapikey(apikey)?; let busservices= Bus::getbusservices(&client, None)?; println!("{:?}", bus_services); Ok(()) }
async fn geterp() -> LTAResult<()> { let apikey = std::env::var("APIKEY").expect("APIKEY not found!"); let client = LTAClient::withapikey(apikey)?; let erprates = Traffic:: geterprates(&client, Some(500))?; println!("{:?}", erp_rates); Ok(()) } ```
There are some instances where you might need to customise the reqwest client due to certain limitations.
```rust use lta::r#async::client::LTAClient; use lta::reqwest::ClientBuilder; use std::time::Duration; use lta::Client;
fn mycustomclient() -> LTAClient { let client = ClientBuilder::new() .nogzip() .connecttimeout(Duration::new(420, 0)) .build() .unwrap();
LTAClient::new("API_KEY", client)
} ```
LTAClient
as it holds a connection pool internallyUpdate Freq
in the documentation and prevent
yourself from getting blacklisted. Use a caching mechanism.Changelog can be found here
lta-rs is licensed under MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
Is this library being actively developed?
Yes. However, development will slow down from mid August 2019 onwards due to my NS commitments.
What are the APIs available?
Take a look at the official LTA docs.
Where do I get the official docs from lta?
You can get them here