Transport For London NodeJS API Wrapper (tfl.api)
Simple NodeJS wrapper API for https://api.tfl.gov.uk/ using superagent and promises.
Installation
npm install tfl.api --save
Contributing
Contributions are welcome. Please submit a pull request. If you encounter any issues, please submit an Issue.
Usage
The Transport for London API requires the use of an app_id
and app_key
. You can register for one at TFL API Portal.
The package can then be used as follows:
var appId = '<YOUR_APP_ID>';var appKey = '<YOUR_APP_KEY>';var tfl = appId appKey;
- Accident Stats
- Bikepoint (TODO)
- Cycle Super Highway (TODO)
- Journey
- Line (TODO)
- Mode (TODO)
- Occupancy
- Place
- Road (TODO)
- Search
- StopPoint
Each type of API can also be required separately as outlined in the examples below. Also see tests for samples.
Below is an outline of methods available to query. This library uses superagent to make HTTP requests. Responses are returned as promises and response content can be accessed through r => response.body
.
Accident Stats
Implements API endpoint as supported by TFL Accident Stats
var tfl = appId appKey;// or var accidentstats = require('tfl.api/accidentstats')(appId, appKey) // Get accident stats for the year 2015tfl
Journey
Implements API endpoint as supported by TFL Journey
var tfl = appId appKey;// or var journey = require('tfl.api/journey')(appId, appKey) var origin = '1001067'; // City Thameslinkvar destination = '1000123' // Kentish Town // Get a journey plan from City Thameslink to Kentish Towntfltfl // Get Meta data for journey given a type as per TFL APItfljourney
Occupancy
Implements API endpoint as supported by TFL Place
var tfl = appId appKey;// or var occupancy = require('tfl.api/occupancy')(appId, appKey); // Get occupancy of all car parkstfloccupancy // Get occupancy of a car park by idtfloccupancy
Place
Implements API endpoint as supported by TFL Place
var tfl = appId appKey;// or var place = require('tfl.api/place')(appId, appKey); // Retrieve a place by ID. Second argument can pass additional query paramstflplace // Retrieve places by lat/lng/radiustfl // Retrieve places within a bounding boxtfl // Get places of the given type at the given latitude and longitudetfl // Get metadatatfl
Search
Implements method supported by TFL Search
var tfl = appId appKey;// or var search = require('tfl.api/search')(appId, appKey); // Search TFL with a querytfl // Search TFL with a query and pagination optionstfl; // Get metadata for search methodstflsearch // Get bus schedulestflsearch
StopPoint
Implements API endpoint as supported by TFL StopPoint
var tfl = appId appKey;// or var stoppoint = require('tfl.api/stoppoint')(appId, appKey); // Gets a list of StopPoints corresponding to the given list of stop ids. tflstoppoint // Retrieve stoppoint by lat/lng/stopTypestfl // Retrieve stoppoint within a bounding boxtfl // Gets the list of arrival predictions for the given stop point id tflstoppoint // Gets Stopoints that are reachable from a station/line combination. Third argument can pass additional query paramstflstoppoint // Gets the canonical direction, "inbound" or "outbound", for a given pair of stop point Ids in the direction from -> to. Third argument can pass additional query paramstflstoppoint // Gets all disruptions for the specified StopPointId, plus disruptions for any child Naptan records it may have. Second argument can pass additional query paramstflstoppoint // Gets all disruptions for the specified StopPointId, plus disruptions for any child Naptan records it may have. Forth argument can pass additional query paramstflstoppoint // Gets metadata for methods that act upon the Stops controller. If metadataType is "categories", gets a list of all of the available stops property categories and keys, grouped by category name. If metadataType is "stoptypes", gets a list of the available types of stops. If metadataType is "modes", gets a list of the valid modes to filter stops by.tflstoppoint // Gets a list of StopPoints filtered by the modes available at that StopPoint. Second argument can pass additional query paramstflstoppoint // Gets a distinct list of disrupted stop points for the given modes. Second argument can pass additional query paramstflstoppoint // Gets a distinct list of disrupted stop points for the given modes with a date range. Forth argument can pass additional query paramstflstoppoint // Returns the route sections for all the lines that service the given stop point ids. Second argument can pass additional query paramstflstoppoint // Search StopPoints by their common name, or their 5-digit Countdown Bus Stop Code. Second argument can pass additional query paramstflstoppoint // Gets the service types for a given stoppoint. Second argument can pass additional query paramstflstoppoint // Gets a StopPoint for a given sms code. Second argument can pass additional query paramstflstoppoint // Gets all stop points of a given type.tflstoppointtype'NaptanCoachBay,NaptanMarkedPoint'