Discourse2 on npm: a TypeScript wrapper for Discourse API

I originally published “discourse2” on npm a year ago, but recently gave it a lot more love. It’s basically a TypeScript / JavaScript SDK for the Discourse API, generated from Discourse’s OpenAPI spec. This makes it very easy to work with:

discourse completion

discourse getTopic type

Usage looks like this:

import Discourse from "discourse2";

const discourse = new Discourse("https://discourse.example.org/", {
  "Api-Key": process.env.DISCOURSE_API_KEY,
  "Api-Username": process.env.DISCOURSE_API_USERNAME,
});

const result = await discourse.listLatestTopics();
console.log(result);

There is also a live demo on CodeSandbox.

Features:

  • The entire Discourse API (that’s published in the OpenAPI spec).
  • Always up-to-date: the OpenAPI spec is checked for changes daily, and the package will automatically rebuild and publish itself on changes. The most recent retrieval is shown as a badge at the top of the README: Discourse API update date
  • Works in both server and browser* environments (*useful for querying public data without API keys and on relevant origin, e.g. latest topics, etc)

Please give it a star on GitHub so I can gauge interest and decide how much more time to spend on this. Feedback welcome. There are a few quirks as mentioned in the Notes section in the README.

7 Likes