Back to Documentation
API Reference
Get Category Posts
Retrieve a paginated list of blog posts filtered by a specific category.
GET
client.getCategoryPosts(slug, page, limit)import { LightweightClient } from 'lightweight-client';
async function getCategoryPosts(slug: string, page: number) {
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.getCategoryPosts(slug, page, 10);
}Parameters
slug
string
required
The category slug to filter posts by. Use the getCategories endpoint to get available slugs.
Example:
technology,business,designpage
number
required
The page number to retrieve. Starts from 1.
limit
number
optional
Number of posts to retrieve per page. Default is 10, maximum is 50.
Response
[
{
"id": string, // Unique identifier (UUID)
"slug": string, // URL-friendly post identifier
"headline": string, // Post title
"metaDescription": string, // SEO meta description
"publishedAt": string, // ISO 8601 timestamp
"createdAt": string, // ISO 8601 timestamp
"readingTime": number, // Estimated reading time in minutes
"image": string, // Featured image URL
"category": {
"title": string, // Category display name
"slug": string // Category URL identifier
},
"tags": string[], // Array of tag strings
"relatedPosts": array, // Array of related post objects
"heroSection": string, // Pre-rendered HTML for hero section
"author": {
"name": string, // Author's display name
"title": string, // Author's title/role
"image": string // Author's avatar URL
},
"navigationMenu": [
{
"id": string, // Section anchor ID
"title": string, // Section heading text
"level": number // Heading level (1-6)
}
]
},
// ... more post objects
]Response Schema
Returns an array of post objects filtered by the specified category. Each post object contains:
idstringUnique identifier for the post
slugstringURL-friendly version of the headline
headlinestringThe main title of the blog post
publishedAtstring (ISO 8601)Timestamp when the post was published
imagestringURL of the featured image
categoryobjectCategory information with title and slug (will match the requested category)
authorobjectAuthor details including name, title, and image
navigationMenuarrayTable of contents for the post
Usage Example
Here's how you might implement category filtering with pagination:
// Get all available categories
const categories = await client.getCategories();
// Get posts from the "technology" category
const techPosts = await client.getCategoryPosts('technology', 1, 10);
// Implement pagination for a category
let currentPage = 1;
const postsPerPage = 10;
async function loadCategoryPage(category: string, page: number) {
const posts = await client.getCategoryPosts(category, page, postsPerPage);
if (posts.length === 0) {
console.log('No more posts in this category');
return;
}
// Render posts
posts.forEach(post => {
console.log(`- ${post.headline} (${post.readingTime} min read)`);
});
}Notes
- •All posts returned will belong to the specified category
- •The response structure is identical to
getPostsbut filtered by category - •Posts are returned in descending order by publication date (newest first)
- •Returns an empty array if the category slug doesn't exist or has no posts
- •Use the DEMO API key
a8c58738-7b98-4597-b20a-0bb1c2fe5772for testing