Back to Documentation
API Reference

Get All Categories

Retrieve a list of all available categories for organizing your blog 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. You can use the DEMO key a8c58738-7b98-4597-b20a-0bb1c2fe5772 for testing - please set it in the root .env.local file');

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

Parameters

This endpoint does not require any parameters.

Response

[
  {
    "slug": "technology",
    "title": "Technology"
  },
  {
    "slug": "business",
    "title": "Business"
  },
  {
    "slug": "design",
    "title": "Design"
  },
  {
    "slug": "marketing",
    "title": "Marketing"
  },
  {
    "slug": "product-updates",
    "title": "Product Updates"
  },
  {
    "slug": "engineering",
    "title": "Engineering"
  },
  {
    "slug": "data-science",
    "title": "Data Science"
  }
]

Response Schema

Returns an array of category objects, each containing:

slugstring

URL-friendly identifier for the category. Used in API calls and routing.

titlestring

Human-readable display name for the category.

Usage Example

Here's how you might use the categories to filter posts:

// Get all categories
const categories = await client.getCategories();

// Display categories in a navigation menu
categories.forEach(category => {
  console.log(`<a href="/blog/${category.slug}">${category.title}</a>`);
});

// Filter posts by category slug
const techPosts = await client.getPostsByCategory('technology');
Notes
  • Categories are predefined in your CMS and cannot be created via the API
  • The slug field is used for URL routing and API filtering
  • Categories are returned in alphabetical order by default
  • Use the DEMO API key a8c58738-7b98-4597-b20a-0bb1c2fe5772 for testing