Skip to content

Latest commit

 

History

History
97 lines (68 loc) · 6.15 KB

README.md

File metadata and controls

97 lines (68 loc) · 6.15 KB

Trips

(trips)

Overview

Timetables and routes for train trips between stations, including pricing and availability.

Available Operations

  • list - Get available train trips

list

Returns a list of available train trips between the specified origin and destination stations on the given date, and allows for filtering by bicycle and dog allowances.

Example Usage

import { TrainTravelSDK } from "train-travel-sdk";

const trainTravelSDK = new TrainTravelSDK({
  oAuth2: process.env["TRAINTRAVELSDK_O_AUTH2"] ?? "",
});

async function run() {
  const result = await trainTravelSDK.trips.list({
    page: 1,
    limit: 10,
    origin: "efdbb9d1-02c2-4bc3-afb7-6788d8782b1e",
    destination: "b2e783e1-c824-4d63-b37a-d8d698862f1d",
    date: new Date("2024-02-01T09:00:00Z"),
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { TrainTravelSDKCore } from "train-travel-sdk/core.js";
import { tripsList } from "train-travel-sdk/funcs/tripsList.js";

// Use `TrainTravelSDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const trainTravelSDK = new TrainTravelSDKCore({
  oAuth2: process.env["TRAINTRAVELSDK_O_AUTH2"] ?? "",
});

async function run() {
  const res = await tripsList(trainTravelSDK, {
    page: 1,
    limit: 10,
    origin: "efdbb9d1-02c2-4bc3-afb7-6788d8782b1e",
    destination: "b2e783e1-c824-4d63-b37a-d8d698862f1d",
    date: new Date("2024-02-01T09:00:00Z"),
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

Parameter Type Required Description
request operations.GetTripsRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.GetTripsResponse>

Errors

Error Type Status Code Content Type
errors.APIError 4XX, 5XX */*