npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

api-railway

v0.1.0

Published

Api wrapper for api.railwayapi.site

Downloads

28

Readme

RailwayAPI NodeJS client

This is an official NPM package that wraps railwayapi API for NodeJS with first class Typescript support.

An example project using this package can be found on Railway Frontend Demo

Example 1 Example 1

Installation

Install this package using npm

npm install api-railway

Getting started

Import the module and create a new client. You can pass different base URL, API version, protocol if you want to use different server.

import Client from 'api-railway'

const client1 = new Client()

const client2 = new Client({
  BASE_URL: 'example.com',
  API_VRSION: 'v1',
  DEFAULT_PROTOCOL: 'https',
})

Every REST method returns a Promise, making this library async await ready. Following examples will use the await form.

Each REST endpoint returns an object with type ApiReturnType

type ApiRetrunType<T extends ApiRetrunDataType, U extends ErrorObj = ErrorObj, V = {}> = {
  httpStatusCode: number
  httpStatusText: string
  responseType: ResponseType
  ok: boolean
  url: string
  responseHeaders: Headers
  data: T[] | undefined
  errors: U[] | undefined
  raw: any
  extra?: V
}

where ApiRetrunDataType is defined as

type ApiRetrunDataType =
  | ScheduleInfo
  | ScheduleRow
  | State
  | StationGeneralInfo
  | StationInfo
  | TrainGeneralInfo
  | TrainInfo
  | TrainsBtwStationsType
  | TrainType
  | Zone

and ErrorObj is defined as

type ErrorObj = {
  httpCode: number
  type: string
  code: string
  title: string
  description: string
  href: string
  path: string
  [key: string]: any
}

Table of Contents

Init

| Param | Type | Required | Default | Info | | ----------- | ----------------- | -------- | ----------------------- | ------------------ | | API_VERSION | String | false | v1 | API version to use | | API_KEY | String | false | | | | BASE_URL | String | false | api.railwayapi.site/api | | | API_TIMEOUT | Number | false | 15000 | | | PROTOCOL | 'http' or 'https' | false | 'https' | |

Public REST Endpoints

Trains

Get specific train info

| Param | Type | Required | Default | Info | | ----------- | ------ | -------- | ------- | ------------------------------------ | | trainNumber | String | true | | Train number of train to be searched |

Return type

ApiRetrunType<TrainInfo, ErrorObj>

Where TrainInfo is

type TrainInfo = {
  id: number
  trainNumber: string
  trainName: string
  trainFullName: string
  stationFrom: { stationCode: string; id: number; stationName: string }
  stationTo: { stationCode: string; id: number; stationName: string }
  departureTime: string
  arrivalTime: string
  duration: string
  trainRunsOn: TrainRunsOnType
  numberOfStops: number
  trainTypeCode: string
  distance: number
  availableClasses: string[]
  avgSpeed: number
  hasPantry: boolean
  returnTrainNumber: string
  updatedAt: string
}

Example:

const response = await client.trains.getTrains('12279')

Get list of train

| Param | Type | Required | Default | Info | | ----- | ------ | -------- | ------- | ------------------------------ | | q | String | true | | Query | | limit | Number | false | 10 | Number of train to be returned |

Return type

ApiRetrunType<TrainGeneralInfo, ErrorObj>

Where TrainGeneralInfo is

export type TrainGeneralInfo = {
  id: number
  trainNumber: string
  trainName: string
}

Example:

const response1 = await client.trains.getTrainsGeneral('122')
const response2 = await client.trains.getTrainsGeneral('122', 20)

Schedule

| Param | Type | Required | Default | Info | | ----------- | ------ | -------- | ------- | ------------------------------------ | | trainNumber | String | true | | Train number of train to be searched |

Return type

ApiRetrunType<ScheduleInfo, ErrorObj>

Where ScheduleInfo is

type ScheduleRow = {
  srNo: string
  stationId: number
  stationName: string
  stationCode: string
  arrivalTime: number | null
  departureTime: string | null
  distance: string
  haltTime: string | null
  dayCount: number
  platform: string | null
  boardingDisabled: boolean
  speed: string
}

Example:

const response = await client.schedules.getSchedules('12279')

Stations

Get station

| Param | Type | Required | Default | Info | | ----------- | ------ | -------- | ------- | -------------------------------------- | | stationCode | String | true | | Station code of station to be searched |

Return type

ApiRetrunType<StationInfo, ErrorObj>

Where StationInfo is

type StationInfo = {
  id: number
  stationCode: string
  stationName: string
  stateName: string
  stationType: string
  numberOfPlatforms: number
  hindiStationName: string
  zones: { zoneName: string; zoneCode: string }
  latitude: string
  longitude: string
  updatedAt: string
}

Example:

const response = await client.stations.getStations('NZM')

Get station list

| Param | Type | Required | Default | Info | | ----- | ------ | -------- | ------- | ----- | | q | String | true | | Query | | limit | Number | false | 10 | |

Return type

ApiRetrunType<StationGeneralInfo, ErrorObj>

Where StationGeneralInfo is

type StationGeneralInfo = {
  id: number
  stationCode: string
  stationName: string
}

Example:

const response = await client.stations.getStationsGeneral('N')

Trains-between-stations

| Param | Type | Required | Default | Info | | --------------- | ------ | -------- | ------- | ----------------- | | fromStationCode | String | true | | From station code | | toStationCode | String | true | | To station code | | date | String | false | | |

Return type

ApiRetrunType<TrainsBtwStationsType, ErrorObj, TrainsBtwStationsExtraType>

Where TrainsBtwStationsType, TrainsBtwStationsExtraType, and StationInfo is

type TrainsBtwStationsType = {
  id: number
  trainNumber: string
  trainName: string
  trainFullName: string
  trainRunsOn: TrainRunsOnType
  availableClasses: string[]
  hasPantry: boolean
  trainType: string
  returnTrainNumber: string
  stationFrom: StationStop
  stationTo: StationStop
  updatedAt: string
  distance: number
  duration: string
}

type TrainsBtwStationsExtraType = {
  stationsInfo: StationInfo[]
}

type StationInfo = {
  id: number
  stationCode: string
  stationName: string
  stateName: string
  zoneCode: string
  stationType: string
  hindiStationName: string
}

Example:

const response = await client.trainsBtwStations.getTrainsBtweenStations('NZM', 'GWL')