Back to Documentation
API Reference

Get Single Post

Retrieve a single blog post by its slug, including full HTML content.

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

async function getPost(slug: string) {
  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.getPost(slug);
}

Parameters

slug
string
required

The URL-friendly identifier of the post (e.g., "getting-started-with-nextjs").

Response

{
  "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",
  "updatedAt": "2024-01-15T10:30:00.000Z",
  "readingTime": 5,
  "image": "https://images.lightweight.so/...",
  "html": "<article>...</article>",
  "category": {
    "title": "Development",
    "slug": "development"
  },
  "tags": [],
  "relatedPosts": [],
  "author": {
    "name": "John Doe",
    "title": "Senior Developer",
    "image": "https://..."
  },
  "navigationMenu": [
    { "id": "introduction", "text": "Introduction", "level": 1 },
    { "id": "setup", "text": "Setup", "level": 2 }
  ]
}

Response Schema

idstring

Unique identifier for the post

slugstring

URL-friendly version of the headline

headlinestring

The main title of the blog post

htmlstring

Clean, semantic HTML content ready to render. Includes proper heading tags, lists, blockquotes, code blocks, and images.

publishedAtstring (ISO 8601)

Timestamp when the post was published

imagestring

URL of the featured image

categoryobject

Category information with title and slug

authorobject | null

Author details including name, title, and image

navigationMenuarray

Table of contents with heading IDs and levels

Notes
  • Returns null if the post is not found or not published
  • The html field contains clean, semantic HTML that you can render directly
  • Use the navigationMenu to build a table of contents sidebar
  • You are responsible for styling the HTML (headings, paragraphs, lists, code blocks, etc.)