# npm上のDiscourse2: Discourse API用のTypeScriptラッパー

**URL:** <https://meta.discourse.org/t/discourse2-on-npm-a-typescript-wrapper-for-discourse-api/328680>\
**Category:** Development\
**Created:** [2024 年 9 月 30 日午後 12:56 UTC](https://meta.discourse.org/t/discourse2-on-npm-a-typescript-wrapper-for-discourse-api/328680 "2024-09-30T12:56:19Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![gadicc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gadicc/32/116696_2.png) [@gadicc](https://meta.discourse.org/u/gadicc)\
**Post date:** [2024 年 9 月 30 日午後 12:56 UTC](https://meta.discourse.org/t/discourse2-on-npm-a-typescript-wrapper-for-discourse-api/328680/1 "2024-09-30T12:56:19Z")

</div>

1年前にnpmで「[discourse2](https://www.npmjs.com/package/discourse2)」を公開しましたが、最近さらに多くの愛情を注ぎました。これは基本的に、DiscourseのOpenAPI仕様から生成されたDiscourse API用のTypeScript / JavaScript SDKです。これにより、非常に簡単に使用できます。

[![discourse completion](https://global.discourse-cdn.com/meta/original/4X/0/a/9/0a9f012b10a7ee0d9825ec0b929be2035effcd46.png)](https://github.com/gadicc/discourse2/blob/dev/assets/discourse-completion.png)

[![discourse getTopic type](https://global.discourse-cdn.com/meta/original/4X/e/f/3/ef3ad1384b1e0aa1c10e4004018d7b7486cb18d7.png)](https://github.com/gadicc/discourse2/blob/dev/assets/discourse-getTopic-type.png)

使い方は以下のようになります。

```ts
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);

```

[CodeSandboxのライブデモ](https://codesandbox.io/p/sandbox/discourse2-dht4ym)もあります。

**機能** ：

- Discourse APIの_すべて_（OpenAPI仕様で公開されているもの）。
- 常に最新：OpenAPI仕様は毎日変更がないかチェックされ、変更があった場合はパッケージが自動的に再構築および再公開されます。最新の取得日は、READMEの先頭にあるバッジに表示されます： ![Discourse API update date](https://global.discourse-cdn.com/meta/original/4X/6/3/4/63499307e314e1fefd8c1f10314876f585a1fdba.svg)
- サーバー環境とブラウザ\*環境の両方で動作します（APIキーなしで公開データ、例えば最新トピックなどをクエリする場合に便利です）。

興味の度合いを測り、どれだけ多くの時間を費やすかを判断するために、[GitHub](https://github.com/gadicc/discourse2)でスターを付けていただけると幸いです。フィードバックも歓迎します。READMEのNotesセクションに記載されているように、いくつかの注意点があります。

---

_[View the full topic](https://meta.discourse.org/t/discourse2-on-npm-a-typescript-wrapper-for-discourse-api/328680)._
