Skip to content
Simple API for public transport realtime data
Rust Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
fixtures
proto
src
tests
.gitignore
Cargo.lock
Cargo.toml
LICENSE
Makefile
README.md
build.rs
example_configuration_file.yml

README.md

transpo-rt

Simple API for public transport realtime data.

This API reads a public transport base schedule (a GTFS) and some realtime data (for the moment in GTFS_RT to provide realtime feeds in siri lite.

Using

A hosted version of this API, with some french datasets can be freely used.

The API provides several routes:

  • GET /: list the available datasets - example call
  • GET /spec: OpenApi v3 description of this API - example call
  • GET /{id}/gtfs-rt: get the gtfs-rt as binary - example call
  • GET /{id}/gtfs-rt.json: get the gtfs-rt as json - example call
  • GET /{id}/siri/2.0/stop-monitoring.json: get a siri-lite stop monitoring response - example call
  • GET /{id}/siri/2.0/stoppoints-discovery.json: get a siri-lite stoppoint discovery response - example call
  • GET /{id}/siri/2.0/general-message.json: get a siri-lite general message response - example call
  • GET /{id}/: simple status on the dataset - example call

API details

/siri/2.0/stop-monitoring.json

The API follow the Siri-lite specification (documentation in french).

A formal description of the supported parameters and of the response can be seen in the OpenAPI endpoint.

/siri/2.0/stoppoints-discovery.json

The API follow the Siri-lite specification (documentation in french).

A formal description of the supported parameters and of the response can be seen in the OpenAPI endpoint.

Developping

Building

To build the api, you need an up to date Rust version:

If you don't already have it, install Rust:

curl https://sh.rustup.rs -sSf | sh

Or update it:

rustup update

Then you can build it:

cargo build

Running

You can check the needed cli parameters with the -h option:

cargo run --release -- -h

Note: an example configuration file can be seen here.

Testing

You can run all the tests (unit test, integration, clippy and fmt) with:

make check

It will save you some time for the code review and continous integration ;)

Architecture

The API has been made with actix-web. This makes it possible to have a multithreaded API with data reloading and realtime updates without dataraces (thanks to rust), nor mutexes (thanks to the actix actor model).

To achieve this there is an Actor in charge of the data (DatasetActor). The api workers query this actor to get the latest data. The DatasetActor does not return directly the data, but a Arc to them (a rust shared pointer).

In the background, 2 actors are in charge of periodic data reloading:

  • BaseScheduleReloader reloads once in a while the baseschedule dataset
  • RealTimeReloader reloads frequently the realtime dataset

Once the data (baseschedule or realtime) has been reloaded, it is send to the DatasetActor via a message. When the DatasetActor processes this message, it replaces it's Arc to this data, dropping the references. The API workers that have aquired an Arc to those data can continue their work on those data. The old data will be deleted when all workers have finished their work on them (thus noboby owns an Arc to those data anymore).

You can’t perform that action at this time.