mtaStatus is a REST API that returns MTA subway status in Json format.
It is written in Rust for all the wonderful reasons, but most importantly the fact that it results in a tiny service. The tiny runtime cost really shines when you deploy it on a raspberryPi, which has become my main source for testing and personal projects.
The MTA is necessary if you live in NYC. It is also highly unreliable :| For this reason we need to keep an eye on which trains are running (especially for those early morning commutes).
- Now you have the option of using the wonderful widget that is provided by the MTA:
- Or maybe we like to view the status on our phones and the lack of a mobile site is annoying, so we look for an api:
- YES that is XML!! But wait is that HTML embedded inside the XML?? YES!
Therefore the nice Json API.
Build for Raspi:
Run from the root project dir:
docker run \ --volume $PWD:/home/cross/project \ --volume ~/.cargo/registry:/home/cross/.cargo/registry \ ragnaroek/rust-raspberry:1.23.0 build --release
copy executable onto your raspi
scp -P 100 target/arm-unknown-linux-gnueabihf/release/mta_status email@example.com:mta_status
Build for Docker on x86:
cargo install cargo-watch
cargo watch -x 'rustc --bin mta-status --features clippy -- -Z no-trans'//assumes nightly(see Cargo.toml)
cargo watch -x 'rustc --lib --features clippy -- -Z no-trans'//assumes nightly(see Cargo.toml)
cargo watch -x run
cargo build --release
cargo rustdoc --lib --open -- --no-defaults --passes collapse-docs --passes unindent-comments --passes strip-priv-imports
Future work (PR's are welcome)
- add better logging
- add better error handling
- don't hit the MTA server on each request and instead cache the response in a local file
- implement the service as multi-threaded
- make a client to use the api :)