Railway Routes Between Stations API

stationRoutes(fromCode: string, toCode: string)

Description

Find railway paths between two station codes from recorded train routes. Results list the stations along each path and rank paths by the number of trains that serve them, then distance.

Parameters

NameInTypeRequiredDescription
fromCodeARGUMENTstringYESOrigin station code, 1-5 letters only
toCodeARGUMENTstringYESDestination station code, 1-5 letters only

Code Example

javascript
import { configure, stationRoutes } from "railkit";

configure(process.env.RAILKIT_API_KEY);

const result = await stationRoutes("NDLS", "DLI");

if (result.success) {
  for (const route of result.data.routes) {
    console.log(route.rank, route.distanceKm, route.stations.map((station) => station.code));
  }
}

Response Example

JSON response
200JSON
{
  "success": true,
  "data": {
    "from": {
      "code": "NDLS",
      "name": "NEW DELHI",
      "lat": 28.642314,
      "lon": 77.220004
    },
    "to": {
      "code": "DLI",
      "name": "DELHI JN",
      "lat": 28.661816,
      "lon": 77.228356
    },
    "routes": [
      {
        "rank": 1,
        "distanceKm": 441,
        "stationCount": 68,
        "intermediateStationCount": 66,
        "stations": [
          {
            "code": "NDLS",
            "name": "NEW DELHI",
            "lat": 28.642314,
            "lon": 77.220004
          },
          {
            "code": "DSB",
            "name": "SADAR BAZAR",
            "lat": 28.6586,
            "lon": 77.2168
          }
        ]
      }
    ],
    "note": "Each returned station sequence is served by the train numbers listed on that route."
  }
}