AstraCMS

Quickstart

Get started with the AstraCMS API in minutes

Prerequisites

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

Choose Your Framework

AstraCMS provides official SDK packages for popular frameworks:

Quick Example with Core Package

Install the core package:

npm install @astracms/core
pnpm add @astracms/core
yarn add @astracms/core
bun add @astracms/core

Basic Usage

app.ts
import { createAstraCMSClient } from '@astracms/core'

const client = createAstraCMSClient({
  apiKey: process.env.ASTRACMS_API_KEY,
})

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

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

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

Using the REST API Directly

If you prefer to use the API directly:

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

Common Use Cases

Fetch posts by category

const techPosts = await client.getPosts({
  categories: ['technology'],
  limit: 5,
})

Fetch posts by tag

const jsPosts = await client.getPosts({
  tags: ['javascript', 'typescript'],
})

Search posts

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

Get content as Markdown

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

Next Steps

Last updated on

On this page