Skip to content

lta-rs/lta-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

lta-rs

🚍 Singapore LTA Datamall async first Rust client. lta-rs is used to interact with lta-datamall

lta-rs in action

Cargo.toml setup

[dependencies]
lta = { version = "0.7.0" }

API key setup

You can get your API key from here

use lta::{LTAResult, LTAClient, Client, Traffic, TrafficRequests};

#[tokio::main]
async fn main() -> LTAResult<()> {
    let api_key = std::env::var("API_KEY").expect("API_KEY not found!");
    let client = LTAClient::with_api_key(api_key)?;
    let erp_rates = Traffic::get_erp_rates(&client, None).await?;
    println!("{:?}", erp_rates);
    Ok(())
}

Feature flags

Feature Description
default (i.e no features added ) Uses reqwest under the hood
reqwest-blocking Uses reqwest::blocking under the hood
ureq-blocking Uses ureq under the hood
fastfloat Enables the fastfloat impl for parsing floats (uses SIMD)
non-blocking-traits Exports traits that can be use to impl non-blocking clients
blocking-traits Exports traits that can be use to impl blocking clients

Feature flags examples

Using ureq only

[dependencies]
lta = { version = "0.7.0", default-features = false, features = ["ureq-blocking"]}

Implementing another blocking backend

[dependencies]
lta = { version = "0.7.0", default-features = false, features = ["blocking-traits"]}

Implementing another async backend

[dependencies]
lta = { version = "0.7.0", default-features = false, features = ["non-blocking-traits"]}

Backend Support

Backend Status Github CI Run :octocat:
reqwest Official βœ” Yes βœ” ️
reqwest blocking Official βœ” ️ Yes βœ”οΈ
ureq Official βœ” ️ Yes βœ”οΈ
surf TBA β­• ️ No β­•

Examples

Example Description
bus_timing.rs How to get bus timing (async used)
reqwest_blocking.rs How to use reqwest blocking feature
ureq_blocking.rs How to use ureq backend
custom_client.rs How to create custom backend clients

General advice

  • Reuse LTAClient<T> as it holds a connection pool internally
  • Reduce the number of times you call the API, take a look at Update Freq in the documentation and prevent yourself from getting blacklisted. Use a caching mechanism.

Getting help

  • You can get help via GitHub issues. I will try my best to respond to your queries πŸ˜„

Changelog

Changelog can be found here

Requirements

  • Rust compiler 1.56

Frequently Asked Questions

Q: Is this library being actively developed?

A: Project is currently in maintenance mode. Won't really have any new features. Just bug fixes, minor upgrades etc.

Q: What are the APIs available?

A: All of the APIs are implemented. Take a look at the official LTA docs.

Q: Where do I get the official docs from lta?

A: You can get them here

License

lta-rs is licensed under MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

Donations

For Singapore based users, you can donate using paylah!