TFL API Wrapper
A rust crate for using the Transport for London (TFL) API.
Note: Only the Line API is currently supported. Other APIs are work in progress
Installation
Using cargo
, add this to your project's Cargo.toml
:
[]
= "0.1.3"
Usage
Get the Keys from TFL API Portal
- If you don't already have an account, register on TFL API Portal.
- Vist the Products link and create a new subscription for
500 Requests per min
(allows 500 requests per min). - Next, visit your profile, scroll down to the
Primary key
section of your subscription, click onShow
and copy the value. You can use either ofPrimary key
orSecondary key
.
Use the crate
Set the APP_KEY
environment variable.
Instantiate the Client
using:
use ;
let client = new;
Here APP_KEY
could be either Primary key
or Secondary key
.
Example
Get the API version:
async
List valid modes
async
List severity types
async
List routes by mode
async
Get arrival predictions by lines
async
Fetch disruptions by mode
async
Tests
You can run the tests by running:
APP_KEY=hjdhajsdas
Developer
As this library maintains a LineID
enum, we have a tool to compare this with
the API's list of valid routes. It reports on the status of LineID
, listing
which lines are missing, which have a mismatched to_string()
mapping and
which are no longer in use.
Run:
APP_KEY=hjdhajsdas
Implemented APIs
- Version - Shows the API version
- Line
- Get all valid routes for all lines, including the name and id of the originating and terminating stops for each route.
- Get all valid routes for given line ids, including the name and id of the originating and terminating stops for each route.
- Get disruptions for all lines of the given modes.
- Get disruptions for the given line ids.
- Get the list of arrival predictions for given line ids based at the given stop
- Gets a list of the stations that serve the given line id
- Gets a list of valid disruption categories
- Gets a list of valid modes
- Gets a list of valid ServiceTypes to filter on
- Gets a list of valid severity codes
- Gets all lines and their valid routes for given modes, including the name and id of the originating and terminating stops for each route
- Gets all valid routes for given line id, including the sequence of stops on each route.
- Gets lines that match the specified line ids
- Gets lines that serve the given modes.
- Gets the line status for all lines with a given severity
- Gets the line status for given line ids during the provided dates e.g Minor Delays
- Gets the line status of for all lines for the given modes
- Gets the line status of for given line ids e.g Minor Delays
- Gets the timetable for a specified station on the give line
- Gets the timetable for a specified station on the give line with specified destination
- Search for lines or routes matching the query string
Limitations
- Currently, the enum types created for Lines does not contain buses starting with numeric characters (e.g. 101).
References/Credits
- Existing tfl wrappers
- tfl-api-wrapper - NodeJS wrapper for TFL API, made with TypeScript.
- tfl-api-wrapper-py - Python wrapper for TFL API
- go-tfl - Go client for TFL API
- Adzuna-rs - For existing wrapper implementation for Adzuna API.