> ## Documentation Index
> Fetch the complete documentation index at: https://buttercms.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# API architecture & principles

> ButterCMS API architecture and performance characteristics for developers integrating headless CMS functionality.

## Core design principles

ButterCMS provides a REST API that serves content through a globally distributed infrastructure. Content created through the dashboard or Write API is immediately available via read endpoints with automatic global distribution for optimized delivery.

### RESTful design

The ButterCMS API follows REST (Representational State Transfer) architecture, which means:

* **Resource-Oriented URLs**: Each URL represents a specific resource (pages, collections, posts)
* **HTTP Methods**: Standard HTTP verbs indicate the action (GET for reading, POST for creating, PUT/PATCH for updating, DELETE for removing)
* **Stateless Requests**: Each request contains all information needed to process it
* **JSON Responses**: All responses use JSON format for consistency and ease of parsing

### Base URL

All API requests are made to:

```
https://api.buttercms.com/v2
```

## Architecture overview

```mermaid theme={null}
flowchart TB
    Pages["Pages<br/><small>• Single Pages<br/>• Page Types</small>"]
    Collections["Collections<br/><small>• Categories<br/>• Products<br/>• Team Members</small>"]
    Blog["Blog Posts<br/><small>• Authors<br/>• Categories<br/>• Tags</small>"]

    Pages <-->|" "| Collections

    Refs["Reference Fields (slugs/IDs)<br/><small>One-to-One or One-to-Many</small>"]
    Pages --> Refs
    Collections --> Refs
```

## Content types

The API supports creating, updating, and deleting items of three main content types:

### Pages

Fully customizable, reusable schemas that are supercharged with features like structured local and global components, form integrations, and repeaters. These can be individually fetched via a slug and are ideal for complex web content requiring flexible layouts and advanced functionality.

### Collections

Lighter-weight, customizable, reusable schemas for tables of data that are fetched via ID. Perfect for structured content like categories, team members, or product catalogs that primarily serve as reference data. Collections are optimized for simpler data structures and faster querying, making them ideal for content that needs to be referenced by Pages or queried directly from the API.

### Blog Posts

Built-in content type from our blog engine, which comes out-of-the-box with categorization, tagging, predefined SEO, and authors. Designed for chronological content with standardized blog functionality and includes features like automated RSS feeds and WordPress import capabilities.

## Global CDN infrastructure

Content delivery operates through Fastly's global CDN with 150+ edge locations, typically serving cached content in under 100ms. Read operations are cached at edge locations with purge-based invalidation: there is no fixed cache lifetime. Publishing, updating, or deleting content triggers a purge of the related cache entries (including content that references the changed content). The purge runs asynchronously, so updates usually appear within seconds.

### Request flow

```mermaid theme={null}
flowchart LR
    Client["Client<br/>Application"]
    CDN["Global CDN<br/><small>(150+ edges)</small>"]
    API["ButterCMS<br/>API"]
    BG["Background<br/>Processing<br/><small>Media Upload<br/>Validation<br/>Webhooks<br/>Cache Refresh</small>"]

    Client --> CDN
    CDN --> API
    API --> BG

    CDN -->|Cache Hit<br/>~50-100ms| Cached["Cached<br/>Response"]

    API -.-|Cache Miss<br/>~200-500ms| CDN
```

### Cache behavior

* **Initial requests** fetch content from the API and populate edge caches (\~200-500ms typical)
* **Subsequent requests** serve from the nearest location (\~50-100ms typical)
* **Content updates** automatically invalidate relevant cache entries globally, including all content that references the changed content

## Publication states

Content can exist in three states:

| State | Description | Access |
| - | - | - |
| **Draft** | Content being edited, not yet live | Preview mode only (`preview=1`) |
| **Published** | Live content accessible via API | Standard API endpoints |
| **Scheduled** | Automatic publication at specified time | Preview until publication time |

State changes trigger system-wide operations including cache invalidation, webhook notifications, and reference resolution across related content.

## Write operations

Create and update operations return `202 Accepted` for immediate feedback while background processing handles tasks like media uploads, validation, and webhook notifications. This ensures consistent fast response times regardless of operation complexity.

## Integration patterns

For easiest implementation, ButterCMS API integration should follow a structured approach of these sequential steps: content architecture planning, API endpoint integration, performance optimization, and production deployment. Content must be designed in your ButterCMS dashboard first to establish schema and reference relationships before implementing API calls in your application.

### Static site generation (SSG)

Implementations fetch content during build processes and utilize webhook-triggered rebuilds for content updates. This pattern provides maximum performance through pre-built pages and CDN distribution but requires build system integration for content synchronization. Build-time fetching typically uses batch API calls to retrieve all necessary content, implementing error handling for API availability during build processes.

```mermaid theme={null}
flowchart LR
    subgraph SSG["SSG (Build Time)"]
        direction LR
        Content --> Build["Build Process"]
        Build --> Static["Static Files"]
        Static --> CDN1["CDN"]
        CDN1 --> Users
        Webhook["Webhook"] -.->|triggers rebuild| Build
    end
```

### Server-side rendering (SSR)

Applications fetch content on each request, implementing application-level caching to optimize performance while maintaining real-time content updates. Request-time fetching allows for personalized content and immediate content updates but requires careful cache management and error handling for API unavailability scenarios.

```mermaid theme={null}
flowchart LR
    subgraph SSR["SSR (Request Time)"]
        direction LR
        Request["User Request"] --> Server
        Server --> API["API Call"]
        API --> Page["Dynamic Page"]
        Page --> User
        Server -.-> Cache["App-level cache"]
    end
```

### Single page applications (SPA)

Client-side content fetching with progressive loading patterns, utilizing browser caching and API response caching for optimal user experience. Client-side integration enables dynamic content updates and interactive experiences but requires consideration of API key security and CORS configuration.

```mermaid theme={null}
flowchart LR
    subgraph SPA["SPA (Client Side)"]
        direction LR
        User2["User"] --> Shell["App Shell"]
        Shell --> APIs["API Calls"]
        APIs --> Updates["Dynamic Updates"]
        Updates --> UI
        Shell -.-> BCache["Browser cache"]
    end
```

## API efficiency

Strategic parameter usage improves performance significantly:

* **`exclude_body=true`**: Omits the `body` field from Blog Post list/search responses for faster listing operations (not available on Pages or Collections endpoints)
* **`levels` parameter**: Controls reference depth (1-5, default 2) to balance data completeness with response time
* **Pagination**: Use appropriate page sizes for large content sets, typically 10-25 items per request for optimal performance (`page_size` defaults to 10 with a maximum of 100)

## Error handling

Implement graceful degradation patterns for API unavailability, retry logic with exponential backoff for transient failures, and fallback content mechanisms for critical application functionality. Applications should monitor API response times and implement circuit breaker patterns for sustained API issues. Content architecture should minimize reference depth requirements and design reference patterns to avoid circular dependencies that impact API performance.

## Key features summary

| Feature | Description |
| - | - |
| **REST Architecture** | Predictable, resource-oriented URLs |
| **JSON Responses** | All responses in JSON format |
| **Global CDN** | 150+ edge locations worldwide |
| **Fast Responses** | Sub-100ms for cached content (typical) |
| **Automatic Caching** | Purge-based invalidation on every content change |
| **Webhooks** | Real-time notifications for content changes |
| **Localization** | Multi-language content support |

## Next steps

> [card] [Authentication](https://buttercms.com/docs/api/concepts/authentication-api-tokens.md)
>
> Learn how to authenticate your API requests

> [card] [REST Endpoints](https://buttercms.com/docs/api/concepts/rest-endpoints-urls.md)
>
> Explore all available API endpoints

> [card] [Request/Response Format](https://buttercms.com/docs/api/concepts/request-response-format.md)
>
> Understand the JSON data structure

> [card] [Error Handling](https://buttercms.com/docs/api/concepts/http-status-codes-errors.md)
>
> Handle errors gracefully


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.