#gtfs #transit #http-request #public-api #transiter

no-std rust_transiter_types

Some generated rust types for the transiter API https://github.com/jamespfennell/transiter. Meant for no std enviromnets that have an alloc.

4 releases

0.1.3 Jan 20, 2025
0.1.2 Jan 20, 2025
0.1.1 Jan 20, 2025
0.1.0 Jan 20, 2025

#4 in #transit

Download history 139/week @ 2025-01-14 146/week @ 2025-01-21

285 downloads per month

MIT license

150KB
2.5K SLoC

Transiter Rust types.

For anyone working with the transiter API in Rust. This crate exposes a no-std rust types for the Transiter APIs in Rust. This is mostly to unblock development in other embedded projects that want to query a transiter server in a type safe way.

Usage

A simple web request to an API could look like this.

use rust_transiter_types::public_api_types::Stop;

#[derive(serde::Deserialize, Debug, Clone)]
struct ApiResponse {
    stops: Vec<Stop>,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let response =
        reqwest::blocking::get("https://demo.transiter.dev/systems/us-ny-subway/stops?limit=3")?;

    if !response.status().is_success() {
        return Err("request failed".into());
    }

    let api_response: ApiResponse = response.json()?;
    let stations = api_response.stops;

    println!("Found {} NYC subway stations:", stations.len());
}

Enum Serialization Support

As of now there might be some issues with using other structs that make use of enums besides Stop.

This is because prost will represent enums as an i32 and it requires custom serialization logic otherwise. I'm adding them one by one.

Dependencies

~2–8MB
~64K SLoC