Examples

The Articles API provides methods to fetch, filter, search, and list articles from your Simplist project.

MethodDescriptionReturns
List articles with pagination and filtersArticleListItem[]
Get a single article by slugArticle
Search articles by queryArticleListItem[]
Get only published articlesArticleListItem[]
Get latest articlesArticleListItem[]
Get popular articlesArticleListItem[]
Generate RSS feed XMLstring

Fetch a complete article by its unique slug, including full content.

get-article.ts
import { SimplistClient } from "@simplist.blog/sdk"

// Uses SIMPLIST_API_KEY from environment variables
const client = new SimplistClient()

const response = await client.articles.get('my-article-slug')

if (response.data) {
  const article = response.data
  console.log(article.title)
  console.log(article.content)
  console.log(article.author.name)
  console.log(`${article.readTimeMinutes} min read`)
}

PropertyTypeDescriptionDefault
id*stringUnique article ID-
title*stringArticle title-
slug*stringURL-friendly identifier-
content*stringFull article content in Markdown-
excerptstring | nullShort summary-
coverImagestring | nullCover image URL-
published*booleanPublication status-
status*stringCurrent status-
viewCount*numberTotal views-
wordCount*numberWord count-
characterCount*numberCharacter count-
lineCount*numberLine count-
readTimeMinutes*numberEstimated reading time-
author*AuthorAuthor information-
lastUpdatedByAuthor | nullLast editor-
createdAt*stringCreation timestamp (ISO 8601)-
updatedAt*stringLast update timestamp-
publishedAtstring | nullPublication timestamp-
variantsRecord<LanguageCode, ArticleVariant>Multilingual variants-

Fetch multiple articles with pagination, sorting, and filtering.

list-articles.ts
const response = await client.articles.list({
  page: 1,
  limit: 20,
  sort: 'createdAt',
  order: 'desc',
  published: true
})

if (response.data) {
  const articles = response.data
  const { page, limit, total, totalPages } = response.meta

  console.log(`Page ${page} of ${totalPages}`)
  console.log(`Showing ${articles.length} of ${total} articles`)
}

PropertyTypeDescriptionDefault
pagenumberPage number for pagination1
limitnumberItems per page10
sort'createdAt' | 'updatedAt' | 'title'Field to sort by'createdAt'
order'asc' | 'desc'Sort order'desc'
publishedbooleanFilter by publication status-
status'draft' | 'published'Filter by specific status-
searchstringSearch query-

List methods return a meta object with pagination information:

pagination.ts
{
  page: 1,           // Current page
  limit: 20,         // Items per page
  total: 157,        // Total items
  totalPages: 8      // Total pages
}

Get the most recent published articles.

latest.ts
// Get 10 latest articles
const response = await client.articles.latest(10)

// Custom limit
const response = await client.articles.latest(25)

This method automatically:

  • Filters to published articles only
  • Sorts by creation date (newest first)
  • Applies the specified limit

Fetch only published articles with custom filters.

published.ts
const response = await client.articles.published({
  page: 1,
  limit: 20,
  sort: 'title',
  order: 'asc'
})

// All parameters are optional
const response = await client.articles.published()

This method is equivalent to list() with published: true.

Get the most viewed articles.

popular.ts
// Get 10 most popular articles
const response = await client.articles.popular(10)

// Custom limit
const response = await client.articles.popular(20)

Note: This currently returns published articles. Sorting by view count may be added in a future API update.

Search articles by title, content, or excerpt.

search.ts
// Simple search
const results = await client.articles.search('React hooks')

// Search with filters
const results = await client.articles.search('React hooks', {
  page: 1,
  limit: 10,
  sort: 'createdAt',
  order: 'desc'
})

The search query matches against:

  • Article title
  • Article excerpt
  • Article content

Create an RSS 2.0 XML feed from your articles.

rss.ts
const xml = await client.articles.rss({
  hostname: 'https://myblog.com',
  title: 'My Blog',
  description: 'Latest articles from my blog',
  limit: 50
})

// In Next.js API route
export async function GET() {
  const xml = await client.articles.rss({
    hostname: process.env.NEXT_PUBLIC_URL
  })

  return new Response(xml, {
    headers: {
      'Content-Type': 'application/xml',
      'Cache-Control': 'public, max-age=3600'
    }
  })
}

PropertyTypeDescriptionDefault
hostname*stringBase URL for article links-
titlestringFeed title"Blog Feed"
descriptionstringFeed description"Latest articles"
limitnumberMax articles50

All methods return an ApiResponse<T> with error handling built in.

error-handling.ts
try {
  const response = await client.articles.get('article-slug')

  if (response.data) {
    console.log(response.data.title)
  }
} catch (error) {
  if (error instanceof SimplistApiError) {
    console.error(`API Error [${error.statusCode}]: ${error.message}`)
  } else {
    console.error('Unexpected error:', error)
  }
}

StatusErrorSolution
404Article not foundCheck the slug is correct
401UnauthorizedVerify your API key
403ForbiddenCheck API key permissions
429Rate limit exceededWait before retrying
500Server errorRetry with exponential backoff

complete-example.ts
import { SimplistClient } from "@simplist.blog/sdk"

const client = new SimplistClient({
  apiKey: process.env.SIMPLIST_API_KEY
})

// Fetch latest articles for homepage
async function getHomepageArticles() {
  const response = await client.articles.latest(6)
  return response.data || []
}

// Fetch article for blog post page
async function getArticle(slug: string) {
  const response = await client.articles.get(slug)

  if (!response.data) {
    return null
  }

  return response.data
}

// Paginated article list
async function getArticlePage(page: number = 1) {
  const response = await client.articles.published({
    page,
    limit: 12,
    sort: 'publishedAt',
    order: 'desc'
  })

  return {
    articles: response.data || [],
    pagination: response.meta
  }
}

// Search functionality
async function searchArticles(query: string) {
  if (!query.trim()) {
    return []
  }

  const response = await client.articles.search(query, {
    limit: 20
  })

  return response.data || []
}

Quick Help

Use ISR (Incremental Static Regeneration) with revalidate for better performance. Set revalidate: 60 to rebuild pages every minute, or use on-demand revalidation when content changes.
Wrap the SDK call in try-catch and use Next.js notFound() function for 404 errors. This shows your custom 404 page instead of an error page.
Yes! Use the SDK in generateStaticParams() to pre-render all articles at build time. This is perfect for static blogs with infrequent updates.

Command Palette

Search for a command to run...