SDKs overview

transport.rest provides a standardized API for accessing public transport information across various providers and cities. To facilitate developer integration, transport.rest offers official and community-contributed Software Development Kits (SDKs) and libraries. These tools abstract the underlying HTTP requests and JSON parsing, allowing developers to interact with the transport.rest API using language-specific constructs. The primary focus of official support is on JavaScript, reflecting its prevalence in web and Node.js-based applications, which are common environments for consuming public transit data services.

SDKs typically handle authentication, request formatting, response parsing, and error handling, reducing the boilerplate code required to build applications. For example, a well-designed SDK can simplify the process of finding a public transport journey between two points or retrieving real-time departure information for a specific station. While JavaScript is officially supported, the open-source nature of transport.rest encourages the development of community-driven libraries in other programming languages, extending its reach to diverse development ecosystems. These community contributions enable developers to integrate transport.rest data into applications built with languages like Python, Ruby, or Java, depending on available libraries.

Official SDKs by language

The transport.rest project officially maintains a JavaScript SDK designed to provide a direct and idiomatic interface to its API. This SDK is published and managed through standard package managers for the JavaScript ecosystem, ensuring ease of discovery and installation. The official SDK aims to cover the full range of API functionalities, including querying for journeys, retrieving station data, and accessing real-time updates. Developers can find comprehensive documentation and usage examples for the official JavaScript SDK on the transport.rest official documentation portal.

The table below summarizes the key details of the official SDK available for transport.rest:

Language Package Name Install Command Maturity
JavaScript transport-rest-client npm install transport-rest-client or yarn add transport-rest-client Stable

Installation

Installing the official JavaScript SDK for transport.rest is performed using standard package managers for Node.js projects, such as npm or Yarn. Before installation, developers should ensure they have Node.js and one of these package managers installed on their system. Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine, widely used for server-side applications and development tooling (Node.js npm getting started guide). This setup is standard for most modern JavaScript development environments.

To install the transport-rest-client package:

  1. Using npm: Open your terminal or command prompt, navigate to your project directory, and execute the following command:
    npm install transport-rest-client
    This command downloads the package and its dependencies and adds it to your project's node_modules folder, updating your package.json and package-lock.json files.
  2. Using Yarn: Alternatively, if you prefer Yarn as your package manager, use this command:
    yarn add transport-rest-client
    Yarn performs a similar function to npm, managing project dependencies efficiently (transport.rest client on Yarnpkg).

Once installed, the SDK can be imported into your JavaScript or TypeScript files, enabling access to its functions and classes for interacting with the transport.rest API. The installation process typically takes a few seconds, depending on network speed and system resources.

Quickstart example

This quickstart example demonstrates how to use the official JavaScript SDK to retrieve real-time departure information for a specific station. This snippet assumes the transport-rest-client package has been successfully installed in your project. The first step involves importing the necessary client from the installed package. Then, an instance of the client is created, which can be configured with an API key if required for commercial use or higher rate limits, although transport.rest is free for non-commercial use with limited requests. For demonstration purposes, this example might not explicitly show API key configuration if the endpoint is accessible without one or uses a publicly available test key.

To obtain specific station identifiers or other parameters used in the query, developers typically consult the transport.rest API reference documentation. This documentation provides details on available endpoints, required parameters, and expected response formats. The example focuses on a common use case: fetching departures from a known station ID, which is a fundamental operation for many transit applications.


import { createClient } from 'transport-rest-client';

// Initialize the client. For public, non-commercial use, an API key might not be strictly necessary
// for basic queries, but it's good practice to configure it if you have one.
// const client = createClient({ apiKey: 'YOUR_API_KEY' });
const client = createClient();

const stationId = '900000001004'; // Example: Berlin Hauptbahnhof (main station)

async function getDepartures() {
  try {
    const departures = await client.departures(stationId);
    console.log(`Departures from ${stationId}:`);
    departures.forEach(departure => {
      console.log(`  ${departure.line.name} to ${departure.direction} at ${new Date(departure.when).toLocaleTimeString()}`);
    });
  } catch (error) {
    console.error('Error fetching departures:', error.message);
  }
}

getDepartures();

This JavaScript code snippet will connect to the transport.rest API via the SDK, request departure data for the specified station ID, and then log the relevant information to the console. The createClient function initializes the SDK, and the departures method is called with the station ID as an argument. The await keyword handles the asynchronous nature of API calls, ensuring the response is received before processing. Error handling is included to catch potential issues during the API request, such as network problems or invalid station IDs. This example serves as a foundation for building more complex features, such as real-time departure boards, journey planners, or transit alerts.

Community libraries

While transport.rest officially supports only a JavaScript SDK, the open-source nature and clear API specification have encouraged the development of community-contributed libraries in other programming languages. These libraries often wrap the core HTTP API in a way that is idiomatic to their respective languages, providing developers with familiar interfaces and patterns. Community efforts are crucial for expanding the reach of transport.rest to a broader developer audience, allowing integration into diverse application stacks beyond the JavaScript ecosystem.

Developers seeking libraries in languages such as Python, Ruby, PHP, or Java should explore public code repositories like GitHub or GitLab. Searching for terms like transport.rest-python, transport.rest-ruby, or similar queries can often yield relevant projects. It is important to note that the maturity, maintenance, and feature completeness of community libraries can vary significantly. Before integrating a community library, it is advisable to check its documentation, the date of its last update, the number of active contributors, and any reported issues.

When evaluating community libraries, consider the following aspects:

  • Active Maintenance: Libraries that are regularly updated tend to be more reliable and compatible with the latest API changes.
  • Documentation: Comprehensive documentation, including installation instructions and usage examples, is a strong indicator of a well-maintained library.
  • Community Support: The presence of an active community, through issue trackers or forums, can provide valuable assistance and insights.
  • Feature Coverage: Verify that the library supports the specific transport.rest API endpoints and functionalities required for your project.
  • License: Understand the licensing terms of the library, especially for commercial projects.

Developers who create new community libraries are encouraged to share them, potentially by contributing to the transport.rest documentation or community forums, to help grow the ecosystem. Such contributions often follow open-source best practices, typically hosted on platforms providing version control and collaborative development features, such as GitHub topics for transport.rest, where various related projects might be found.