TfL API TypeScript Client Demo

A demonstration component showcasing the `tfl-ts` npm package - a fully-typed TypeScript client for the Transport for London (TfL) API. Features real-time London transport data, live status updates, and comprehensive coverage of all TfL services including Tube, Bus, DLR, Overground, and more.

v0.0.1
🍰
🏃
🎓
Beginner

TfL API TypeScript Client Demo

A demonstration of the tfl-ts npm package - a fully-typed TypeScript client for the Transport for London (TfL) API. This component showcases real-time London transport data using the published npm library.

About the Library

The tfl-ts package provides:

  • Zero dependencies - Lightweight and fast
  • Fully typed - Complete TypeScript support with auto-generated types
  • Real-time data - Live transport status and arrivals
  • Comprehensive coverage - All TfL endpoints including Tube, Bus, DLR, Overground, and more
  • Modern API - Built with modern TypeScript practices

Installation

npm install tfl-ts

Basic Usage

import TfLClients from "tfl-ts";

const tfl = new TfLClients();

// Get tube status
const tubeStatus = await tfl.line.getStatus({ modes: ['tube'] });

// Get arrivals for a station
const arrivals = await tfl.stopPoint.getArrivals({ id: '940GZZLUPAC' });

// Plan a journey
const journey = await tfl.journey.getJourney({
  from: '940GZZLUPAC',
  to: '940GZZLUVIC',
  date: '2024-01-15',
  time: '09:30'
});

Live Demo

This component demonstrates real-time London transport data using the tfl-ts library:

Live TfL Status

Powered by tfl-ts npm package

Fully Typed
Complete TypeScript support
Zero Dependencies
Lightweight & fast
Real-time Data
Live transport updates

Service Disruptions

Bakerloo

Minor DelaysNo service between Queen's Park and Harrow & Wealdstone following emergency engineering work. Please use the Lioness line to complete your journey. MINOR DELAYS on the rest of the line.
Part SuspendedNo service between Queen's Park and Harrow & Wealdstone following emergency engineering work. Please use the Lioness line to complete your journey. MINOR DELAYS on the rest of the line.

Suffragette

Minor DelaysNo service between Barking and Barking Riverside due to a signal failure at Barking. MINOR DELAYS on the rest of the line.
Part SuspendedNo service between Barking and Barking Riverside due to a signal failure at Barking. MINOR DELAYS on the rest of the line.

Good Service(18 lines)

Central

Northern

Jubilee

Piccadilly

District

Victoria

Circle

Hammersmith & City

Metropolitan

Waterloo & City

DLR

Tram

Elizabeth line

Liberty

Lioness

Mildmay

Weaver

Windrush

Data provided by Transport for London via the tfl-ts npm package. Updated in real-time.

Key Features Demonstrated

  • Real-time Status Updates - Live transport line status with severity indicators
  • Visual Line Representation - Authentic TfL line colors and branding
  • Smart Sorting - Lines with issues prioritized, good service grouped
  • Responsive Design - Works across all device sizes
  • Accessibility - Proper ARIA labels and keyboard navigation
  • Dark Mode Support - Seamless theme switching

API Coverage

The library supports all major TfL services:

  • Underground - All 11 tube lines
  • Overground - London Overground network
  • DLR - Docklands Light Railway
  • Elizabeth Line - Crossrail services
  • Tram - London Tramlink
  • Bus - All London bus routes
  • River Services - Thames Clippers
  • Cable Car - Emirates Air Line

Type Safety

Every API response is fully typed:

// Fully typed responses
const status: LineStatus[] = await tfl.line.getStatus({ modes: ['tube'] });
const arrivals: Arrival[] = await tfl.stopPoint.getArrivals({ id: '940GZZLUPAC' });
const journey: Journey[] = await tfl.journey.getJourney({ from: 'A', to: 'B' });

Error Handling

The library provides comprehensive error handling:

try {
  const status = await tfl.line.getStatus({ modes: ['tube'] });
} catch (error) {
  if (error instanceof TfLError) {
    console.log('TfL API Error:', error.message);
  }
}

Performance

  • Zero dependencies - No bloat
  • Tree-shakable - Only import what you use
  • Caching support - Built-in request caching
  • Batch requests - Efficient API usage

Links