Back to Documentation
API Reference

Get All Posts

Retrieve a paginated list of all published blog posts.

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

async function getPosts(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.getPosts(page, 10);
}

Parameters

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 with Next.js",
      "publishedAt": "2024-01-15T10:30:00.000Z",
      "createdAt": "2024-01-14T08:00:00.000Z",
      "readingTime": 5,
      "image": "https://images.lightweight.so/...",
      "category": {
        "title": "Development",
        "slug": "development"
      },
      "tags": [],
      "author": {
        "name": "John Doe",
        "title": "Senior Developer",
        "image": "https://..."
      },
      "navigationMenu": [
        { "id": "introduction", "text": "Introduction", "level": 1 },
        { "id": "setup", "text": "Setup", "level": 2 }
      ]
    }
  ],
  "total": 42,
  "pagination": {
    "page": 0,
    "limit": 10,
    "total": 42,
    "totalPages": 5,
    "hasMore": true
  }
}

Response Schema

idstring

Unique identifier for the post

slugstring

URL-friendly version of the headline

headlinestring

The main title of the blog post

publishedAtstring (ISO 8601)

Timestamp when the post was published

imagestring

URL of the featured image

categoryobject

Category information with title and slug

authorobject

Author details including name, title, and image

navigationMenuarray

Table of contents for the post

Notes
  • Posts are returned in descending order by publication date (newest first)
  • Only published posts are returned (posts with a publishedAt date)
  • The html content is not included in the list response for performance