✨Typescript promise based wrapper for National Rail SOAP API.
Based on API docs found here
- Yarn 🧶
- 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 } = require("ts-national-rail-wrapper")
const apiKey = "****-****-****-****"
const nationalRail = new NationalRailWrapper(apiKey)
...
const results = await nationalRail.getDepartures({ fromStation: "LDS", count: 5 })
const options = { fromStation: "LDS", count: 5 }
const results = await nationalRail.getDepartures(options)
const options = { fromStation: "LDS", count: 5 }
const results = await nationalRail.getArrivals(options)
const options = { fromStation: "LDS", count: 10 }
const results = await nationalRail.getAll(options)
const options = { serviceId: "RAIL_SERVICE_001" }
const results = await nationalRail.getServiceDetails(options)
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
🚂🚃🚃🚃🚃🚃✨