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/clientpnpm add @astra-cms/clientyarn add @astra-cms/clientbun add @astra-cms/clientBasic Usage
Using the SDK
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:
curl -X GET "https://api.astracms.com/v2/posts" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"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