Lightweight Client Documentation

Learn how to integrate Lightweight Client into your blog to fetch and display articles.

!

Prerequisites

Before you begin, make sure you have completed the following:

  • 1

    Create a Lightweight Account

    Sign up at lightweight.so to access the portal

  • 2

    Set Up Your Project

    Create a new project in the portal and configure your blog settings

  • 3

    Generate an API Key

    Navigate to → API Keys in your project dashboard to find your unique API key

Note: You can use the demo key a8c58738-7b98-4597-b20a-0bb1c2fe5772 for testing. Add it to your .env.local file.

1

Install Lightweight Client

First, install the lightweight-client package in your project.

npm install lightweight-client

Demo API Key Available

You can use the demo key a8c58738-7b98-4597-b20a-0bb1c2fe5772 for testing. Add it to your .env.local file.

2

Initialize Client & Fetch Data

Learn how to initialize the Lightweight Client and fetch blog posts.

Get All Posts (for Blog Page)

Use this function to fetch a paginated list of blog posts for your blog overview page.

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);
}

Get Single Post (for Article Page)

Use this function to fetch a specific blog post by its slug for individual article pages.

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);
}
Environment Variables

Add your API key to your environment variables file:

Next.js (.env.local)

LIGHTWEIGHT_API_KEY=your-api-key-here

React (.env)

REACT_APP_LIGHTWEIGHT_API_KEY=your-api-key-here

Vue/Vite (.env)

VITE_LIGHTWEIGHT_API_KEY=your-api-key-here