transitland-rest-client
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

transitland-rest-client

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.

Features

📦 Zero Dependencies

✅ Typed Responses

📃 Automatic Pagination

🚦 Automatic Rate Limiting

🆔 Onestop ID Utilities

Getting Started

Install

npm install transitland-rest-client

Example

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";

Package Sidebar

Install

npm i transitland-rest-client

Weekly Downloads

2

Version

0.2.0

License

MIT

Unpacked Size

105 kB

Total Files

25

Last publish

Collaborators

  • danthonywalker