No description
  • TypeScript 98.5%
  • Shell 0.8%
  • JavaScript 0.7%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-07-16 11:26:52 +09:00
.github Remove sleepless from codeowners. (#899) 2026-03-17 12:22:45 -04:00
.husky Migrate from yarn to pnpm. (#236) 2024-01-28 22:08:00 -05:00
scripts API docs without RequestState (#977) 2026-06-03 09:20:12 -04:00
src Ran copy script (#1009) 2026-07-14 10:23:01 -04:00
.gitignore Auto-generating swagger / OpenAPI docs using tsoa and redocly (#458) 2025-01-27 13:22:44 -05:00
.prettierignore Update dependency eslint to v10.2.0 (#915) 2026-04-06 08:42:21 -04:00
.prettierrc.json Add community language (#85) 2022-12-19 10:57:02 -05:00
.woodpecker.yml Update dependency prettier to v3.8.5 (#1000) 2026-07-03 09:19:04 -04:00
CHANGELOG.md Updating git cliff. (#361) 2024-09-27 20:24:25 +00:00
cliff.toml Updating git cliff. (#361) 2024-09-27 20:24:25 +00:00
eslint.config.mjs API docs without RequestState (#977) 2026-06-03 09:20:12 -04:00
LICENSE Initial commit. 2020-08-19 13:29:37 -04:00
package.json 1.0.0-resolve-reason.0 2026-07-16 11:26:52 +09:00
pnpm-lock.yaml Update dependency prettier to v3.8.5 (#1000) 2026-07-03 09:19:04 -04:00
pnpm-workspace.yaml Update pnpm to v11 (#944) 2026-05-12 10:49:09 -04:00
putTypesInIndex.js Wrap responses in RequestState (#946) 2026-05-17 14:14:51 -04:00
README.md API docs without RequestState (#977) 2026-06-03 09:20:12 -04:00
renovate.json Changing renovate to monthly (#1007) 2026-07-03 15:15:27 +02:00
tsconfig.json Update dependency typescript to v6 (#912) 2026-04-06 09:38:35 -04:00
tsoa.json Enable more lints (#897) 2026-03-24 10:23:12 +01:00

GitHub tag (latest SemVer) GitHub issues License GitHub stars

lemmy-js-client

A javascript / typescript http client and type system for Lemmy.

Installation

pnpm install lemmy-js-client

Usage

HTTP Client

LemmyHttp docs

import { LemmyHttp, Login } from "lemmy-js-client";

// Build the client
const baseUrl = "https://lemmy.ml";
const headers = {["x-real-ip": ...]};
const client: LemmyHttp = new LemmyHttp(baseUrl, {
  headers,
  useRequestState: true
});

// Build the login form
const loginForm: Login = {
  username_or_email: "my_name",
  password: "my_pass",
};

// Login and set the client headers with your jwt
const loginRes = await client.login(loginForm);

// Make sure its successful
if (loginRes.state === "success") {
  const jwt = login.data.jwt;
  client.setHeaders({ Authorization: `Bearer ${jwt}` });
} else if (loginRes.state === "failed") {
  const err = login.err;
}

// Fetch top posts for the day
const getPostsForm: GetPosts = {
  sort: "TopDay",
  type_: "Local",
};
const postsRes = await client.getPosts(getPostsForm);

// Handle the different request states
switch (postsRes.state) {
  case "empty": {
    break;
  }
  case "loading": {
    break;
  }
  case "failed": {
    const err = postsRes.err;
    break;
  }
  case "success": {
    const data = postsRes.data;
    break;
  }
}

Development

Use pnpm add to develop and test changes locally:

pnpm add path/to/lemmy-js-client

Alternatively, use yalc publish and yalc add lemmy-js-client

Generating typescript types from lemmy structs

Run ./scripts/copy_generated_types_from_lemmy.sh

OpenAPI

To generate OpenAPI docs, run pnpm tsoa

This creates two files:

  • redoc-static.html - A static html rendering of the OpenAPI docs.
  • tsoa_build/swagger.json - An OpenAPI / Swagger json file.

To contribute, check out the tsoa docs.