Easy to use, minimal, and simple implementation of the Transitland v2 REST API for fetching GTFS, GTFS Realtime, GBFS, and MDS data in Javascript and/or Typescript.
npm install transitland-rest-client
import type { FeedResponse } from "transitland-rest-client";
import Client, { EntityType, OnestopId } from "transitland-rest-client";
const client = new Client("YOUR_API_KEY_HERE");
// or
// const client = new Client({
// apiKey: "YOUR_API_KEY_HERE",
// baseUrl: "https://transit.land/api/v2/rest"
// });
const { feeds } = await client.fetch<FeedResponse>("feeds");
// or
// const { feeds } = await client.fetch<FeedResponse>("/feeds");
// const { feeds } = await client.fetch<FeedResponse>({
// path: "feeds",
// query: {
// limit: "100",
// spec: "gbfs",
// }
// });
// Automatically paginate with the same options as above
const pages = client.paginateFetch<FeedResponse>("feeds");
for await (const { feeds } of pages) {
}
// Onestop ID Utilities
const { onestop_id } = feeds[0]; // f-9q9-caltrain
OnestopId.entityTypeOf(onestop_id) === EntityType.Feed;
OnestopId.geohashOf(onestop_id) === "9q9";
OnestopId.nameof(onestop_id) === "caltrain";
const onestopId = OnestopId.parse(onestop_id);
onestopId.entityType === EntityType.Feed;
onestopId.geohash === "9q9";
onestopId.name === "caltrain";