Information services for trains in the UK, using the National Rail open API


Build Status Version License Platform

Information services for trains in the UK, using the National Rail open API

The API is a stab at a friendlier interface for the National Rail Live Departure Boards Web Service


TrainInformationService can be installed using Swift Package Manager or CocoaPods.

Swift Package Manager

Swift Package Manager requires Swift version 4.0 or higher. First, create a Package.swift file. It should look like:

dependencies: [
  .package(url: "", from: "0.1.0"),

swift build should then pull in and compile TrainInformationService for you to begin using.


To install it, simply add the following line to your Podfile:

pod 'TrainInformationService'

Getting Started


In order to use this framework you need a token for National Rail Enquiries LDBWS (OpenLDBWS). You can register for free and receive you token here - For more information about the available APIs the National Rail offers you can read here -

After you get your token you can instantiate the service like this:

import TrainInformationService

let trainInformationService = TrainInformationService(
  apiUrl: "",
  token: "your-token-goes-here")

Currently the service has support for two of the OpenLDWS methods. Both are asynchronous as they are fetching the data in real time from the National Rail Live Departure Boards Web Service. For a full list of methods and documentation you can go here -

Get the station board for a given station (GetStationBoard)

You can find the list of stations with their CSR codes here -

let stationCSRCode = "PAD" // Paddington
let paddingtonBoard = await trainService.stationBoard(for: stationCSRCode, items: 10)

The resulting StationBoard would be an object with a generatedAt date, full origin and destination names, and an array of up to 10 DepartingService objects.

Filtering by destiantion

You can fetch results only to a specific destination, using its CSR code

let originCSRCode = "KGX" // Kings Cross
let destinationCSRCode = "FPK" // Finsbury Park
let filteredBoard = await trainService.stationBoard(for: originCSRCode, to: destinationCSRCode, items: 10)

Get the live departure board for a given station (GetDepartureBoard)

let stationCSRCode = "PAD" // Paddington
trainInformationService.departureBoard(for: stationCSRCode, items: 5) { result in
	switch result {
	case .success(let board):
	case .error(_):

The resulting board would be an array of up to 5 DepartingService objects.

Get service next stops (GetServiceDetails)

Given you have a service ID (e.g. a DepartingService object from the above call), you can get a list of stops remaining on its schedule by doing this:

trainInformationService.serviceDetails(service.serviceId) { callingPoints in

Here callingPoints is an array of CallingPoint objects.


Contributions are welcome! Just submit a PR.


Dimitar Chakarov,


This is free and unencumbered software released into the public domain. See the LICENSE file for more info.


  • Swift Tools 4.2.0
View More Packages from this Author


Last updated: Mon Feb 26 2024 20:39:24 GMT-1000 (Hawaii-Aleutian Standard Time)