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:
Core Package
Universal TypeScript client
React
React hooks for data fetching
Next.js
RSC support with caching
Vue
Vue 3 composables
Nuxt
Nuxt 3 module with auto-imports
Svelte
Svelte stores & SvelteKit
Astro
Content Collection loaders
Quick Example with Core Package
Install the core package:
npm install @astracms/corepnpm add @astracms/coreyarn add @astracms/corebun add @astracms/coreBasic Usage
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:
curl -X GET "https://api.astracms.dev/v2/posts" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"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