Back to Documentation
API Reference

Get All Categories

Retrieve a list of all categories that have published posts.

GET
client.getCategories()
import { LightweightClient } from 'lightweight-client';

async function getCategories() {
  const key = process.env.LIGHTWEIGHT_API_KEY;
  if (!key) throw Error('LIGHTWEIGHT_API_KEY environment variable must be set');

  const client = new LightweightClient(key);
  return client.getCategories();
}

Parameters

This endpoint takes no parameters.

Response

[
  {
    "title": "Development",
    "slug": "development"
  },
  {
    "title": "Design",
    "slug": "design"
  },
  {
    "title": "Marketing",
    "slug": "marketing"
  }
]

Response Schema

titlestring

Display name of the category

slugstring

URL-friendly identifier for the category

Notes
  • Only categories with at least one published post are returned
  • Use the slug to fetch posts by category
  • Returns an empty array if no categories exist