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
,design
page
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": "82c68fd5-48e9-48d8-ac50-a3272150e5c8",
"slug": "ai-revolutionizing-development",
"headline": "How AI is Revolutionizing Software Development",
"metaDescription": "Explore the transformative impact of AI on modern software development practices",
"publishedAt": "2025-09-15T16:48:06.448Z",
"createdAt": "2025-09-15T16:48:06.563Z",
"readingTime": 8,
"image": "https://seoai-blog.s3.amazonaws.com/...",
"category": {
"title": "Technology",
"slug": "technology"
},
"tags": ["AI", "Machine Learning", "Development"],
"relatedPosts": [],
"heroSection": "<!-- HTML content for hero section -->",
"author": {
"name": "Sarah Chen",
"title": "Senior Tech Writer",
"image": "https://seoai-blog.s3.amazonaws.com/..."
},
"navigationMenu": [
{
"id": "introduction",
"title": "Introduction",
"level": 1
},
{
"id": "ai-tools",
"title": "AI-Powered Development Tools",
"level": 2
}
]
},
{
"id": "c9609bf0-3a6a-4849-a18a-bd2fed8f9c0e",
"slug": "quantum-computing-breakthrough",
"headline": "Quantum Computing: The Next Frontier",
"metaDescription": "Understanding quantum computing and its potential applications",
"publishedAt": "2025-09-13T13:28:42.796Z",
"createdAt": "2025-09-13T13:28:42.901Z",
"readingTime": 12,
"image": "https://seoai-blog.s3.amazonaws.com/...",
"category": {
"title": "Technology",
"slug": "technology"
},
"tags": ["Quantum", "Computing", "Future Tech"],
"relatedPosts": [],
"heroSection": "<!-- HTML content for hero section -->",
"author": {
"name": "Dr. Michael Roberts",
"title": "Tech Researcher",
"image": "https://seoai-blog.s3.amazonaws.com/..."
},
"navigationMenu": []
}
]
Response Schema
Returns an array of post objects filtered by the specified category. Each post object contains:
id
stringUnique identifier for the post
slug
stringURL-friendly version of the headline
headline
stringThe main title of the blog post
publishedAt
string (ISO 8601)Timestamp when the post was published
image
stringURL of the featured image
category
objectCategory information with title and slug (will match the requested category)
author
objectAuthor details including name, title, and image
navigationMenu
arrayTable 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
getPosts
but 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-0bb1c2fe5772
for testing