A simple Rust client for interacting with the Massachusetts Bay Transport Authority's V3 API*
*This project is not affiliated with any official development work from the MBTAThe MBTA V3 API is described as:
A fast, flexible, standards-based API for schedules, arrival predictions, vehicle locations, and service alerts.
This project provides a simple synchronous client and data models to easily consume data from the API within your Rust code.
Why provide a synchronous client rather than an asynchronous one?
async
runtimeureq
crate for its simple API and small size, and it only provides a synchronous clientWhy not auto-generate a client, given that the OpenAPI/Swagger client code-generators exists?
It is highly recommended to have the API Swagger docs handy, as it generally contains more detailed and thorough documentation for model field than what is provided here.
In your Cargo.toml
file:
```toml
[dependencies]
mbta-rs = "*"
chrono = "" serde_json = "" ```
Simple example usage: ```rust use std::{collections::HashMap, env}; use mbta_rs::Client;
let client = match env::var("MBTATOKEN") { Ok(token) => Client::withkey(token), Err() => Client::withoutkey() };
let queryparams = HashMap::from([ ("page[limit]".tostring(), "3".to_string()) ]);
let alertsresponse = client.alerts(queryparams); if let Ok(response) = alerts_response { for alert in response.data { println!("MBTA alert: {}", alert.attributes.header); } } ```
See CONTRIBUTE.md to get started!
README
and CONTRIBUTE
layouts