SDKs overview
Contentstack offers Software Development Kits (SDKs) and client libraries designed to facilitate interaction with its headless Content Management System (CMS) APIs. These tools abstract the complexities of HTTP requests, authentication, and response parsing, allowing developers to focus on integrating content into their applications. The SDK ecosystem includes official libraries maintained by Contentstack, as well as community-contributed tools, covering a range of programming languages and front-end frameworks. The aim is to enable efficient content retrieval and management for various digital experiences, from web applications built with modern JavaScript frameworks to native mobile applications and server-side integrations.
The SDKs are built to interact primarily with Contentstack's Delivery API (for content retrieval) and, in some cases, the Management API (for programmatic content creation and updates). They often incorporate features such as query builders, caching mechanisms, and type definitions to enhance developer experience and application performance. Contentstack emphasizes a composable architecture, which is supported by these SDKs, enabling seamless integration with other services in a modern tech stack.
Official SDKs by language
Contentstack provides official SDKs for a broad spectrum of programming languages and popular frameworks, ensuring developers can integrate the CMS into diverse application environments. These SDKs are maintained by Contentstack and are designed to offer robust, up-to-date functionality consistent with the platform's API capabilities. They typically include methods for fetching entries, assets, and content types, along with support for advanced queries and localization. For detailed usage instructions and API specifics, developers can refer to the official Contentstack SDK documentation.
| Language/Framework | Package Name | Install Command (npm/pip/composer/etc.) | Maturity |
|---|---|---|---|
| JavaScript | contentstack |
npm install contentstack or yarn add contentstack |
Stable |
| React | @contentstack/react-sdk |
npm install @contentstack/react-sdk |
Stable |
| Next.js | @contentstack/nextjs-sdk |
npm install @contentstack/nextjs-sdk |
Stable |
| Gatsby | gatsby-source-contentstack |
npm install gatsby-source-contentstack |
Stable |
| Vue.js | @contentstack/vue-sdk |
npm install @contentstack/vue-sdk |
Stable |
| Angular | @contentstack/angular-sdk |
npm install @contentstack/angular-sdk |
Stable |
| Swift (iOS) | Contentstack (via CocoaPods/Swift Package Manager) |
pod 'Contentstack' or SwiftPM integration |
Stable |
| Kotlin (Android) | com.contentstack.sdk:contentstack (via Gradle) |
implementation 'com.contentstack.sdk:contentstack:+' |
Stable |
| PHP | contentstack/contentstack-php |
composer require contentstack/contentstack-php |
Stable |
| Ruby | contentstack |
gem install contentstack |
Stable |
| Python | contentstack_sdk |
pip install contentstack_sdk |
Stable |
| .NET (C#) | Contentstack.Core (via NuGet) |
dotnet add package Contentstack.Core |
Stable |
Installation
Installation varies depending on the programming language and package manager. For JavaScript-based projects (Node.js, React, Next.js, Vue.js, Angular), npm or yarn are typically used. Python projects leverage pip. PHP projects use Composer, while Ruby projects use Bundler or gem. Mobile development with Swift and Kotlin often relies on platform-specific dependency managers like CocoaPods/Swift Package Manager for iOS and Gradle for Android.
JavaScript / TypeScript (for Web Frameworks and Node.js)
# Using npm
npm install contentstack
# Using yarn
yarn add contentstack
Python
pip install contentstack_sdk
PHP
composer require contentstack/contentstack-php
Ruby
# Add to your Gemfile
gem 'contentstack'
# Then run
bundle install
Swift (iOS) with CocoaPods
# Add to your Podfile
pod 'Contentstack'
# Then run
pod install
Kotlin (Android) with Gradle
// In your app/build.gradle file
dependencies {
implementation 'com.contentstack.sdk:contentstack:+'
}
After installation, configuration typically involves initializing the SDK with API credentials (API Key, Delivery Token, Environment, and Stack API Key). Contentstack provides specific instructions for JavaScript SDK initialization and other language-specific setups in their documentation.
Quickstart example
This quickstart example demonstrates how to fetch content from Contentstack using the JavaScript SDK. It assumes you have an API Key, Delivery Token, and Environment configured in your Contentstack stack. The example fetches entries from a content type named 'blog_post'.
import * as Contentstack from 'contentstack';
// Initialize the Contentstack SDK with your credentials
const Stack = Contentstack.Stack({
api_key: 'YOUR_API_KEY', // Replace with your Stack API Key
delivery_token: 'YOUR_DELIVERY_TOKEN', // Replace with your Delivery Token
environment: 'YOUR_ENVIRONMENT', // Replace with your environment name (e.g., 'development' or 'production')
region: Contentstack.Region.US // Specify your stack's region (e.g., US, EU, AZURE_NA, ASIA_PACIFIC)
});
async function fetchBlogPosts() {
try {
// Fetch entries from the 'blog_post' content type
const queryResult = await Stack.ContentType('blog_post')
.Query()
.includeFallback()
.toJSON()
.find();
const entries = queryResult[0]; // The first element contains the entries array
if (entries && entries.length > 0) {
console.log('Fetched Blog Posts:');
entries.forEach(post => {
console.log(`- Title: ${post.title}`);
console.log(` URL: ${post.url}`);
// Access other fields as defined in your content type
});
} else {
console.log('No blog posts found.');
}
} catch (error) {
console.error('Error fetching blog posts:', error);
}
}
// Call the function to fetch blog posts
fetchBlogPosts();
This snippet initializes the SDK with placeholder credentials. Developers must replace 'YOUR_API_KEY', 'YOUR_DELIVERY_TOKEN', and 'YOUR_ENVIRONMENT' with their actual Contentstack stack credentials. The region parameter should also be set correctly based on where the Contentstack stack is hosted. The .includeFallback() method is used to retrieve content even if the specified locale is not available, falling back to the stack's master locale, as detailed in Contentstack's entry documentation. This approach demonstrates a basic query to retrieve content and log key fields.
Community libraries
Beyond the official SDKs, the Contentstack developer community contributes various libraries, plugins, and integrations that extend the platform's functionality and simplify development workflows. These community-driven tools often address specific use cases, integrate with niche frameworks, or provide advanced features not yet covered by official SDKs. While not officially supported by Contentstack, these resources can offer valuable solutions for developers.
Examples of community contributions might include:
- Starter Kits: Pre-configured projects with Contentstack integration for popular frameworks like Svelte, Eleventy, or Astro, allowing for rapid project setup.
- CLI Tools: Command-line interface utilities that automate common Contentstack operations, such as content migration, schema synchronization, or environment management.
- Custom Field Extensions: UI extensions for the Contentstack content entry experience, built by developers to integrate third-party services or enhance content editing.
- Framework-specific Adapters: Libraries that provide a more idiomatic way to interact with Contentstack within a particular framework, beyond what an official SDK might offer.
Developers interested in exploring community contributions should consult the Contentstack Marketplace and community forums, where such projects are often shared. For example, the broader headless CMS ecosystem often sees community contributions for static site generators or specific rendering pipelines, as noted by resources like Google's documentation on JavaScript SEO basics, which indirectly highlights the need for flexible content delivery solutions that community efforts can support.
When using community libraries, it is advisable to review their documentation, community support, and maintenance status, as their stability and compatibility with future Contentstack API updates may vary compared to official SDKs.