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.

9 Likes

Love the project, thanks a lot :heart:

1 Like

Hi all, thanks for all the likes and support. A few updates:

:white_check_mark: 86% test coverage; mostly E2E on a real Discourse instance. I think basically everything that works with system user, I need to experiment with other users for some methods.

:white_check_mark: Squashed a bunch of bugs along the way, mostly related to PUT requests and redirects.

:white_check_mark: Published to JSR with 100% quality score. All versions are still jointly published to NPM too.

:white_check_mark: Improved TSDocs. Include description too when available, and not just summary. Also @module docs and @example’s.

:white_check_mark: Developed in Deno v2 for a fast, convenient develop experience. Still fully tested in node on every commit, but, alternate runtime friendly!

:white_check_mark: 425 weekly downloads on NPM (but presumably mostly due to bots and release frequency :sweat_smile:).

I’m just about done with this for now. Still want to spend a bit more work on validation safety (and maybe some type coersion) but this is being used on real projects with good effect. Please open any issues for bugs or feature requests, and happy discoursing! :tada:

3 Likes