Learn how to set up SimplyStack and make your first API call. Get up and running in less than 5 minutes.
Getting Started with SimplyStack
Welcome to SimplyStack! This guide will walk you through setting up your first project, installing the SDK, and making your first API call. SimplyStack is a powerful backend-as-a-service platform that provides content management, file storage, and data APIs out of the box.
Prerequisites
- Node.js 18+ installed on your machine
- A SimplyStack account (sign up at https://simplystack.dev)
- Basic knowledge of JavaScript/TypeScript
Step 1: Create Your Project
First, create a new project in your SimplyStack dashboard. This will generate your API credentials and set up your backend services.
- Log in to your SimplyStack dashboard
- Click "New Project" in the top right
- Enter your project name and description
- Select your preferred region
- Click "Create Project"
Step 2: Install the SDK
Install the SimplyStack TypeScript SDK in your project:
npm install @simplystack-org/sdk
# or
yarn add @simplystack-org/sdk
# or
pnpm add @simplystack-org/sdkStep 3: Initialize the Client
Create a new file called `simplystack.js` (or `simplystack.ts` for TypeScript) and initialize your client:
import { SimplyStack } from '@simplystack-org/sdk';
// Initialize the client with your project credentials
const client = new SimplyStack({
projectId: 'your-project-id',
apiKey: 'your-api-key',
// Optional: specify environment
environment: 'production' // or 'staging', 'development'
});
export default client;You can find your Project ID and API Key in your project settings in the SimplyStack dashboard. Keep these credentials secure and never expose them in client-side code.
Step 4: Your First API Call
Let's create your first content item using the Content API:
import client from './simplystack.js';
async function createFirstPost() {
try {
// Create a new content item
const post = await client.content.create({
title: 'My First Post',
slug: 'my-first-post',
type: 'blog',
status: 'published',
content: {
blocks: [
{
type: 'header',
data: {
text: 'Hello, SimplyStack!',
level: 1
}
},
{
type: 'paragraph',
data: {
text: 'This is my first post created with SimplyStack.'
}
}
]
}
});
console.log('Post created:', post);
return post;
} catch (error) {
console.error('Error creating post:', error);
}
}
// Call the function
createFirstPost();Step 5: Fetch Your Content
Now let's retrieve the content we just created:
async function fetchPosts() {
try {
// Get all published posts
const posts = await client.content.list({
type: 'blog',
status: 'published',
limit: 10
});
console.log('Posts:', posts.data);
// Get a specific post by slug
const specificPost = await client.content.getBySlug('my-first-post');
console.log('Specific post:', specificPost);
return posts;
} catch (error) {
console.error('Error fetching posts:', error);
}
}
fetchPosts();Working with Files
SimplyStack also provides a powerful file storage API. Here's how to upload and manage files:
async function uploadFile() {
try {
// Upload a file (works with File objects in browser or Buffer in Node.js)
const file = new File(['Hello, world!'], 'hello.txt', { type: 'text/plain' });
const uploadedFile = await client.storage.upload({
file: file,
path: 'documents/hello.txt',
metadata: {
description: 'My first uploaded file',
tags: ['example', 'text']
}
});
console.log('File uploaded:', uploadedFile);
// Get file URL for public access
const fileUrl = client.storage.getPublicUrl(uploadedFile.path);
console.log('Public URL:', fileUrl);
return uploadedFile;
} catch (error) {
console.error('Error uploading file:', error);
}
}
uploadFile();Advanced Features
SimplyStack offers many advanced features to help you build scalable applications:
- Real-time subscriptions with WebSocket support
- Advanced querying with filters, sorting, and pagination
- Content relationships and references
- File transformations and image optimization
- Webhook integrations for external services
- Role-based access control and authentication
- Analytics and usage tracking
TypeScript Example
The SimplyStack SDK is built with TypeScript and provides full type safety. Here's a complete TypeScript example:
import { SimplyStack, ContentItem, CreateContentRequest } from '@simplystack-org/sdk';
// Define your content types
interface BlogPost extends ContentItem {
title: string;
slug: string;
excerpt?: string;
author: string;
publishedAt: Date;
}
class BlogManager {
private client: SimplyStack;
constructor(projectId: string, apiKey: string) {
this.client = new SimplyStack({ projectId, apiKey });
}
async createPost(data: CreateContentRequest): Promise<BlogPost> {
const post = await this.client.content.create<BlogPost>({
...data,
type: 'blog',
status: 'published'
});
return post;
}
async getAllPosts(): Promise<BlogPost[]> {
const response = await this.client.content.list<BlogPost>({
type: 'blog',
status: 'published',
sortBy: 'publishedAt',
sortOrder: 'desc'
});
return response.data;
}
async getPostBySlug(slug: string): Promise<BlogPost | null> {
try {
const post = await this.client.content.getBySlug<BlogPost>(slug);
return post;
} catch (error) {
return null;
}
}
}
// Usage
const blogManager = new BlogManager(
process.env.SIMPLYSTACK_PROJECT_ID!,
process.env.SIMPLYSTACK_API_KEY!
);
export default blogManager;Next Steps
Congratulations! You've successfully set up SimplyStack and made your first API calls. Here are some recommended next steps:
- Explore the API Reference to learn about all available endpoints
- Check out the Examples section for common use cases
- Set up webhooks to integrate with external services
- Configure your content types and validation rules
- Set up authentication for user-generated content
- Deploy your application to production
Need Help?
If you run into any issues or have questions, we're here to help:
- Check our comprehensive API documentation
- Browse examples and tutorials in our Examples section
- Join our community Discord server
- Contact our support team at support@simplystack.dev
- Report bugs or request features on GitHub