lta-rs
🚍 Singapore LTA Datamall Rust Client written in pure rust with support for asynchronous requests. lta-rs is used to interact with the lta-datamall
lta-rs in action
Cargo.toml setup
[]
# features available: async, blocking. If you only need blocking requests, choose blocking vice versa.
= { = "0.4.0", = ["blocking", "async"] }
API key setup
You can get your API key from here
use *;
Examples
use *;
use LTAClient;
use get_arrival;
// All the APIs in this library are designed to be used like this
// `lta::blocking::module::get_something`
// All of them return lta::utils::LTAResult<Vec<T>>
// The example below is bus::get_bus_services()
// and traffic::get_erp_rates()
// Do note that the API calling convention is similar across all the APIs except for
// bus::get_arrival
// prefer lta::prelude::* over glob imports
// Most of the APIs returns only 500 record
// If you want to get records 501 - 1000 take a look at get_erp() example
use *;
use ;
Async Example
use env;
use *;
use r#;
async
Custom Client
use *;
use Duration;
use ClientBuilder;
use LTAClient;
Concurrent requests without Futures
use Arc;
use spawn;
use ;
use *;
General advice
- Reuse
LTAClient
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. - Prefer
async
APIs over writing your own implementations for concurrent requests.
Getting help
- You can get help via GitHub issues. I will try my best to respond to your queries :smile:
Design decisions
- Made sure that Rust structs are as close to the original response as possible so that people can reference the original docs if there are any issues
- Simple and no additional baggage. Only the client is included. E.g If anyone wants to add concurrency, they have to do it on their own
- Predictable API usage
Changelog
Changelog can be found here
Requirements
On Linux:
- OpenSSL 1.0.1, 1.0.2, or 1.1.0 with headers (see https://github.com/sfackler/rust-openssl)
On Windows and macOS:
- Nothing.
lta-rs uses rust-native-tls internally, which will use the operating system TLS framework if available, meaning Windows and macOS. On Linux, it will use OpenSSL 1.1.
Todo (excluding bugs from issues)
- Proper date types using chrono library
- Utils cleanup
- Host on crates.io
- Static website to showcase project
- Documentation
- More idiomatic Rust code
- Asynchronous requests
- AzurePipelines
- Documentation for async
-
std::future
- Customisable
Client
- Better testing, reduce API spam and cache data for testing
- Deserialization benchmark
License
lta-rs is licensed under MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
Frequently Asked Questions
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