hafas 1.0.0

Client for the HAFAS ReST public transport API
Documentation

hafas

Client for the HAFAS ReST public transport API, for the dialect versions 2.39 and 2.52.

Part of rmv.

It covers location.name, location.nearbystops, departureBoard, arrivalBoard, trip, journeyDetail and recon. The crate has no default server and no policy for the access key: the caller passes both.

use hafas::{Client, DepartureBoard, Error};

async fn departures(access_id: String) -> Result<(), Error> {
    let client = Client::builder("https://example.org/hapi/")
        .access_id(access_id)
        .build()?;
    let board = client.send(&DepartureBoard::new("3000010")).await?;
    for departure in &board.departures {
        println!("{} {}", departure.event.time, departure.event.name);
    }
    Ok(())
}

The access key

The access key is a query parameter, so every request URL contains it. The client keeps it out of everything it hands back:

  • Client::url builds a URL without the key, and Debug hides it.
  • Errors carry no URL, and texts from the server have the key replaced.
  • The debug log of a request shows the URL without the key.
  • Without a key, send returns Error::AccessIdMissing before it opens a connection.

The client does not retry. Whether and how often to try again is up to the caller; Error::retry_after gives the wait the server asked for.

Versions

Servers send their serverVersion and dialectVersion in every answer, and the client logs both at debug level. The types read the fields of both dialect versions and keep enum values they do not know in Other, so a newer server does not break decoding.

schema/ holds a reduced extract of the XSD and the WADLs of both versions: names, types, enums and cardinality. The tests check every field of the types and every request parameter against it.