ts-national-rail-wrapper
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

TS National Rail Wrapper

npm version npm downloads types included publish size

✨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 } = require("ts-national-rail-wrapper")
 
const apiKey = "****-****-****-****"
const nationalRail = new NationalRailWrapper(apiKey)
 
...
 
const results = await nationalRail.getDepartures({ fromStation: "LDS", count: 5 })

Methods

getDepartures - Retrieve Departures for Station

const options = { fromStation: "LDS", count: 5 }
const results = await nationalRail.getDepartures(options)

getArrivals - Retrieve Arrivals for Station

const options = { fromStation: "LDS", count: 5 }
const results = await nationalRail.getArrivals(options)

getAll - Retrieve Both Departures and Arrivals for Station

const options = { fromStation: "LDS", count: 10 }
const results = await nationalRail.getAll(options)

getServiceDetails - Retrieve Details about a certain Rail Service

const options = { serviceId: "RAIL_SERVICE_001" }
const results = await nationalRail.getServiceDetails(options)

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


🚂🚃🚃🚃🚃🚃✨

Package Sidebar

Install

npm i ts-national-rail-wrapper

Weekly Downloads

18

Version

1.0.7

License

MIT

Unpacked Size

14.3 kB

Total Files

11

Last publish

Collaborators

  • rahman95