Starter KitAstraCMS

Quickstart

Get started with the AstraCMS API in minutes

Prerequisites

  • An AstraCMS account with a workspace
  • An API key from your workspace settings

Installation

Install the AstraCMS client library for your preferred language:

npm install @astra-cms/client
pnpm add @astra-cms/client
yarn add @astra-cms/client
bun add @astra-cms/client

Basic Usage

Using the SDK

app.ts
import { AstraClient } from '@astra-cms/client'

const client = new AstraClient({
  apiKey: process.env.ASTRA_API_KEY,
})

// Fetch all posts
const { posts, pagination } = await client.posts.list({
  limit: 10,
  page: 1,
})

// Fetch a single post by slug
const post = await client.posts.get('my-first-post')

console.log(post.title, post.content)

Using the REST API

If you prefer to use the API directly:

List posts
curl -X GET "https://api.astracms.com/v2/posts" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"
Get a single post
curl -X GET "https://api.astracms.com/v2/posts/my-first-post" \
  -H "Authorization: Bearer YOUR_API_KEY"

Common Use Cases

Fetch posts by category

const techPosts = await client.posts.list({
  categories: 'technology',
  limit: 5,
})

Fetch posts by tag

const jsPosts = await client.posts.list({
  tags: 'javascript,typescript',
})

Search posts

const results = await client.posts.list({
  query: 'getting started',
})

Get content as Markdown

const post = await client.posts.get('my-post', {
  format: 'markdown',
})

Next Steps

Last updated on

On this page