Back to Documentation
API Reference

Get Category Posts

Retrieve a paginated list of posts filtered by category.

GET
client.getCategoryPosts(slug, page, limit)
import { LightweightClient } from 'lightweight-client';

async function getCategoryPosts(categorySlug: string, page: number) {
  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.getCategoryPosts(categorySlug, page, 10);
}

Parameters

slug
string
required

The category slug to filter by (e.g., "development").

page
number
required

The page number to retrieve (0-indexed).

limit
number
optional

Number of posts to retrieve per page. Default is 10.

Response

{
  "articles": [
    {
      "id": "abc123",
      "slug": "getting-started-with-nextjs",
      "headline": "Getting Started with Next.js",
      "metaDescription": "Learn how to build modern web apps",
      "publishedAt": "2024-01-15T10:30:00.000Z",
      "readingTime": 5,
      "image": "https://images.lightweight.so/...",
      "category": {
        "title": "Development",
        "slug": "development"
      },
      "author": {
        "name": "John Doe",
        "title": "Senior Developer",
        "image": "https://..."
      }
    }
  ],
  "total": 15,
  "pagination": {
    "page": 0,
    "limit": 10,
    "total": 15,
    "totalPages": 2,
    "hasMore": true
  }
}
Notes
  • Response format is identical to getPosts()
  • Returns empty array if category doesn't exist or has no posts
  • Use getCategories() first to get valid category slugs