TS National Rail Wrapper
✨Typescript promise based wrapper for National Rail SOAP API.
Based on API docs found here
Prerequisite
- Yarn 🧶
Usage
- Apply for an
API_KEY
to be used with the API from National Rail - Require package using Yarn
- Use it 🚀
Yarn:
yarn add ts-national-rail-wrapper
Example Usage:
const NationalRailWrapper = const apiKey = "****-****-****-****"const nationalRail = apiKey ... const results = await nationalRail
Methods
getDepartures - Retrieve Departures for Station
const options = fromStation: "LDS" count: 5 const results = await nationalRail
getArrivals - Retrieve Arrivals for Station
const options = fromStation: "LDS" count: 5 const results = await nationalRail
getAll - Retrieve Both Departures and Arrivals for Station
const options = fromStation: "LDS" count: 10 const results = await nationalRail
getServiceDetails - Retrieve Details about a certain Rail Service
const options = serviceId: "RAIL_SERVICE_001" const results = await nationalRail
Tests
Currently tests will use the actual National Rail API to make calls and test data returned, this works but can cause the tests to be flaky due to the ever changing nature of data.
In an ideal situation these API results should be mocked to have the same behaviour all the time, this is a possible improvement I could make.
Tests make use of the dotenv
lib which will look for an apiKey set in the .env
file, please make sure that exists before running test
Once thats all set up run yarn test
to start test suite
🚂🚃🚃🚃🚃🚃✨