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
There are various versions available. If you omit branch = "version_no", you are taking it from master branch
The library is also available on crates.io
[]
= "0.3.0-async-preview-2"
API key setup
You can get your API key from here
extern crate lta;
use *;
Examples
Getting bus timings
use *;
use LTAClient;
use get_arrival;
Getting anything else
// All the APIs in this library are designed to be used like this
// `module::get_something`
// All of them return lta::utils::Result<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
use *;
use LTAClient;
use get_erp_rates;
use get_bus_services;
Async Example
use r#;
use var;
Custom Client
There are some instance where you might need to customise the client more due to certain limitations.
use Duration;
use ClientBuilder;
use LTAClient;
use Client;
Concurrent requests without Futures
use Arc;
use spawn;
use LTAClient;
use Client;
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 to make sure 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
Version 0.1
- All endpoints that are available from lta datamall website
- Configuration using API
Version 0.2 [ Breaking Changes ]
- Changed all API to take in
<AClientrather than using a globalLTAClient
Version 0.2.1
- Updated dependencies to latest version as of
21 July 2019
Version 0.2.2 [ Broken get_bus_stops, yanked from crates.io ]
- Updated
LTAClient::with_api_keyto create a LTAClient
Version 0.2.3
- Hotfix for broken
lta::bus::get_bus_stopswhich will panic due to typo in serde rename
Version 0.3.0-async-preview-1 [ Breaking Changes ]
- Client trait, now has 2 clients, one with async capabilities
- Currently using
futures-preview = "0.3.0-alpha.17"andtokio = "0.1.22"
Version 0.3.0-async-preview-2 [ Breaking Changes ]
- Re-exports to ensure computability
- Removed
futures-preview = "0.3.0-alpha.17" - Examples for all API, with the exception of
async
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
- Travis CI
- 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
Where do I get the official docs from lta?
You can get them here
Why are some of the datatypes different from the lta documentation?
Some of the datatypes returned are not ideal such as returning lat and lang as string rather than number. Some of the types are also converted to enums to reduce the number of stringly typed stuff
My application panicked.
Check if your API key is valid, if it is and your application still panics because of this library, create a github issue
Is this project affiliated to LTA or any government body?
No.