RESTHeart Cloud is coming soon! Stay tuned!
RESTHeart Cloud Examples and Use Cases
🔧 Configuration
Discover how RESTHeart Cloud accelerates development across different industries and application types. Each example shows how you can get from idea to working backend in minutes.
Web Applications
E-commerce Product Catalog
Build a complete product management system with inventory, categories, and search capabilities.
Setup (2 minutes)
cURL
# Create collections
curl -i -X PUT [INSTANCE-URL]/products \
-H "Authorization: Basic [BASIC-AUTH]"
curl -i -X PUT [INSTANCE-URL]/categories \
-H "Authorization: Basic [BASIC-AUTH]"
curl -i -X PUT [INSTANCE-URL]/inventory \
-H "Authorization: Basic [BASIC-AUTH]"
HTTPie
# Create collections
http PUT [INSTANCE-URL]/products \
Authorization:"Basic [BASIC-AUTH]"
http PUT [INSTANCE-URL]/categories \
Authorization:"Basic [BASIC-AUTH]"
http PUT [INSTANCE-URL]/inventory \
Authorization:"Basic [BASIC-AUTH]"
JavaScript
// Create collections
const createCollections = async () => {
const headers = {
'Authorization': 'Basic [BASIC-AUTH]'
};
fetch('[INSTANCE-URL]/products', {
method: 'PUT',
headers
})
.then(response => {
if (response.ok) {
console.log('Products collection created successfully');
} else {
console.error('Failed to create products collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
fetch('[INSTANCE-URL]/categories', {
method: 'PUT',
headers
})
.then(response => {
if (response.ok) {
console.log('Categories collection created successfully');
} else {
console.error('Failed to create categories collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
fetch('[INSTANCE-URL]/inventory', {
method: 'PUT',
headers
})
.then(response => {
if (response.ok) {
console.log('Inventory collection created successfully');
} else {
console.error('Failed to create inventory collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
createCollections();
Sample Data
cURL
# Add categories
curl -i -X POST [INSTANCE-URL]/categories \
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
-d '{"name": "Electronics", "slug": "electronics", "description": "Electronic devices and accessories"}'
# Add products
curl -i -X POST [INSTANCE-URL]/products \
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
-d '{
"name": "Wireless Headphones",
"sku": "WH-001",
"price": 99.99,
"category": "electronics",
"description": "High-quality wireless headphones with noise cancellation",
"features": ["Bluetooth 5.0", "30-hour battery", "Active noise cancellation"],
"inStock": true,
"quantity": 50,
"tags": ["audio", "wireless", "premium"]
}'
HTTPie
# Add categories
http POST [INSTANCE-URL]/categories \
Authorization:"Basic [BASIC-AUTH]" \
Content-Type:application/json \
name="Electronics" \
slug="electronics" \
description="Electronic devices and accessories"
# Add products
http POST [INSTANCE-URL]/products \
Authorization:"Basic [BASIC-AUTH]" \
Content-Type:application/json \
name="Wireless Headphones" \
sku="WH-001" \
price:=99.99 \
category="electronics" \
description="High-quality wireless headphones with noise cancellation" \
features:='["Bluetooth 5.0", "30-hour battery", "Active noise cancellation"]' \
inStock:=true \
quantity:=50 \
tags:='["audio", "wireless", "premium"]'
JavaScript
// Add categories
const addCategory = () => {
fetch('[INSTANCE-URL]/categories', {
method: 'POST',
headers: {
'Authorization': 'Basic [BASIC-AUTH]',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: "Electronics",
slug: "electronics",
description: "Electronic devices and accessories"
})
})
.then(response => {
if (response.ok) {
console.log('Category created successfully');
} else {
console.error('Failed to create category:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Add products
const addProduct = () => {
fetch('[INSTANCE-URL]/products', {
method: 'POST',
headers: {
'Authorization': 'Basic [BASIC-AUTH]',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: "Wireless Headphones",
sku: "WH-001",
price: 99.99,
category: "electronics",
description: "High-quality wireless headphones with noise cancellation",
features: ["Bluetooth 5.0", "30-hour battery", "Active noise cancellation"],
inStock: true,
quantity: 50,
tags: ["audio", "wireless", "premium"]
})
})
.then(response => {
if (response.ok) {
console.log('Product created successfully');
} else {
console.error('Failed to create product:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Execute
addCategory();
addProduct();
Advanced Queries
cURL
# Search products by name
curl -i "[INSTANCE-URL]/products" --data-urlencode "filter={'name':{$regex:'headphones',$options:'i'}}"
# Filter by price range
curl "[INSTANCE-URL]/products" --data-urlencode "filter={'price':{$gte:50,$lte:150}}"
# Get products with low inventory
curl "[INSTANCE-URL]/products" --data-urlencode "filter={'quantity':{$lt:10}}"
# Category-based filtering with sorting
curl "[INSTANCE-URL]/products" --data-urlencode "filter={'category':'electronics'}" --data-urlencode "sort={price:1}"
HTTPie
# Search products by name
http GET [INSTANCE-URL]/products filter=="{'name':{\$regex:'headphones',\$options:'i'}}"
# Filter by price range
http GET [INSTANCE-URL]/products filter=="{'price':{\$gte:50,\$lte:150}}"
# Get products with low inventory
http GET [INSTANCE-URL]/products filter=="{'quantity':{\$lt:10}}"
# Category-based filtering with sorting
http GET [INSTANCE-URL]/products filter=="{'category':'electronics'}" sort=="{price:1}"
JavaScript
// Search products by name
const searchByName = () => {
const filter = encodeURIComponent("{'name':{\$regex:'headphones',\$options:'i'}}");
fetch(`[INSTANCE-URL]/products?filter=${filter}`)
.then(response => response.json())
.then(data => {
console.log('Search results:', data);
})
.catch(error => console.error('Error:', error));
};
// Filter by price range
const filterByPriceRange = () => {
const filter = encodeURIComponent("{'price':{\$gte:50,\$lte:150}}");
fetch(`[INSTANCE-URL]/products?filter=${filter}`)
.then(response => response.json())
.then(data => {
console.log('Price range results:', data);
})
.catch(error => console.error('Error:', error));
};
// Get products with low inventory
const getLowInventory = () => {
const filter = encodeURIComponent("{'quantity':{\$lt:10}}");
fetch(`[INSTANCE-URL]/products?filter=${filter}`)
.then(response => response.json())
.then(data => {
console.log('Low inventory products:', data);
})
.catch(error => console.error('Error:', error));
};
// Category-based filtering with sorting
const filterByCategory = () => {
const filter = encodeURIComponent("{'category':'electronics'}");
const sort = encodeURIComponent("{price:1}");
fetch(`[INSTANCE-URL]/products?filter=${filter}&sort=${sort}`)
.then(response => response.json())
.then(data => {
console.log('Category results:', data);
})
.catch(error => console.error('Error:', error));
};
// Execute queries
searchByName();
filterByPriceRange();
getLowInventory();
filterByCategory();
Content Management System
Create a headless CMS for blogs, news sites, or documentation.
Content Structure
cURL
# Create content collections
curl -i -X PUT [INSTANCE-URL]/articles -H "Authorization: Basic [BASIC-AUTH]"
curl -i -X PUT [INSTANCE-URL]/authors -H "Authorization: Basic [BASIC-AUTH]"
curl -i -X PUT [INSTANCE-URL]/media.files -H "Authorization: Basic [BASIC-AUTH]"
# Create author
curl -i -X POST [INSTANCE-URL]/authors \
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
-d '{
"name": "Jane Smith",
"email": "jane@example.com",
"bio": "Tech writer and developer advocate",
"avatar": "https://example.com/avatars/jane.jpg"
}'
# Create article
curl -i -X POST [INSTANCE-URL]/articles \
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
-d '{
"title": "Getting Started with RESTHeart Cloud",
"slug": "getting-started-restheart-cloud",
"content": "RESTHeart Cloud makes backend development incredibly fast...",
"excerpt": "Learn how to build APIs in minutes",
"author": "jane@example.com",
"status": "published",
"publishedAt": "2024-01-15T10:00:00Z",
"tags": ["tutorial", "api", "backend"],
"seo": {
"metaTitle": "Getting Started with RESTHeart Cloud",
"metaDescription": "Complete guide to building APIs with RESTHeart Cloud"
}
}'
HTTPie
# Create content collections
http PUT [INSTANCE-URL]/articles Authorization:"Basic [BASIC-AUTH]"
http PUT [INSTANCE-URL]/authors Authorization:"Basic [BASIC-AUTH]"
http PUT [INSTANCE-URL]/media.files Authorization:"Basic [BASIC-AUTH]"
# Create author
http POST [INSTANCE-URL]/authors \
Authorization:"Basic [BASIC-AUTH]" \
Content-Type:application/json \
name="Jane Smith" \
email="jane@example.com" \
bio="Tech writer and developer advocate" \
avatar="https://example.com/avatars/jane.jpg"
# Create article
http POST [INSTANCE-URL]/articles \
Authorization:"Basic [BASIC-AUTH]" \
Content-Type:application/json \
title="Getting Started with RESTHeart Cloud" \
slug="getting-started-restheart-cloud" \
content="RESTHeart Cloud makes backend development incredibly fast..." \
excerpt="Learn how to build APIs in minutes" \
author="jane@example.com" \
status="published" \
publishedAt="2024-01-15T10:00:00Z" \
tags:='["tutorial", "api", "backend"]' \
seo:='{
"metaTitle": "Getting Started with RESTHeart Cloud",
"metaDescription": "Complete guide to building APIs with RESTHeart Cloud"
}'
JavaScript
// Create content collections
const createContentCollections = () => {
const headers = { 'Authorization': 'Basic [BASIC-AUTH]' };
fetch('[INSTANCE-URL]/articles', { method: 'PUT', headers })
.then(response => {
if (response.ok) {
console.log('Articles collection created successfully');
} else {
console.error('Failed to create articles collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
fetch('[INSTANCE-URL]/authors', { method: 'PUT', headers })
.then(response => {
if (response.ok) {
console.log('Authors collection created successfully');
} else {
console.error('Failed to create authors collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
fetch('[INSTANCE-URL]/media.files', { method: 'PUT', headers })
.then(response => {
if (response.ok) {
console.log('Media file bucket created successfully');
} else {
console.error('Failed to create media collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Create author
const createAuthor = () => {
fetch('[INSTANCE-URL]/authors', {
method: 'POST',
headers: {
'Authorization': 'Basic [BASIC-AUTH]',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: "Jane Smith",
email: "jane@example.com",
bio: "Tech writer and developer advocate",
avatar: "https://example.com/avatars/jane.jpg"
})
})
.then(response => {
if (response.ok) {
console.log('Author created successfully');
} else {
console.error('Failed to create author:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Create article
const createArticle = () => {
fetch('[INSTANCE-URL]/articles', {
method: 'POST',
headers: {
'Authorization': 'Basic [BASIC-AUTH]',
'Content-Type': 'application/json'
},
body: JSON.stringify({
title: "Getting Started with RESTHeart Cloud",
slug: "getting-started-restheart-cloud",
content: "RESTHeart Cloud makes backend development incredibly fast...",
excerpt: "Learn how to build APIs in minutes",
author: "jane@example.com",
status: "published",
publishedAt: "2024-01-15T10:00:00Z",
tags: ["tutorial", "api", "backend"],
seo: {
metaTitle: "Getting Started with RESTHeart Cloud",
metaDescription: "Complete guide to building APIs with RESTHeart Cloud"
}
})
})
.then(response => {
if (response.ok) {
console.log('Article created successfully');
} else {
console.error('Failed to create article:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Execute
createContentCollections();
createAuthor();
createArticle();
Content Delivery
cURL
# Get published articles
curl "[INSTANCE-URL]/articles" --data-urlencode "filter={'status':'published'}" --data-urlencode "sort={publishedAt:-1}"
# Get article by slug
curl "[INSTANCE-URL]/articles" --data-urlencode "filter={'slug':'getting-started-restheart-cloud'}"
# Search articles
curl "[INSTANCE-URL]/articles" --data-urlencode "filter={$text:{$search:'RESTHeart API'}}"
HTTPie
# Get published articles
http GET [INSTANCE-URL]/articles filter=="{'status':'published'}" sort=="{publishedAt:-1}"
# Get article by slug
http GET [INSTANCE-URL]/articles filter=="{'slug':'getting-started-restheart-cloud'}"
# Search articles
http GET [INSTANCE-URL]/articles filter=="{\$text:{\$search:'RESTHeart API'}}"
JavaScript
// Get published articles
const getPublishedArticles = () => {
const filter = encodeURIComponent("{'status':'published'}");
const sort = encodeURIComponent("{publishedAt:-1}");
fetch(`[INSTANCE-URL]/articles?filter=${filter}&sort=${sort}`)
.then(response => response.json())
.then(data => {
console.log('Published articles:', data);
})
.catch(error => console.error('Error:', error));
};
// Get article by slug
const getArticleBySlug = (slug) => {
const filter = encodeURIComponent(`{'slug':'${slug}'}`);
fetch(`[INSTANCE-URL]/articles?filter=${filter}`)
.then(response => response.json())
.then(data => {
console.log('Article:', data);
})
.catch(error => console.error('Error:', error));
};
// Search articles
const searchArticles = (query) => {
const filter = encodeURIComponent(`{\$text:{\$search:'${query}'}}`);
fetch(`[INSTANCE-URL]/articles?filter=${filter}`)
.then(response => response.json())
.then(data => {
console.log('Search results:', data);
})
.catch(error => console.error('Error:', error));
};
// Execute
getPublishedArticles();
getArticleBySlug('getting-started-restheart-cloud');
searchArticles('RESTHeart API');
Mobile Applications
Social Media App Backend
Build a complete social platform with users, posts, likes, and real-time features.
User Profiles and Posts
cURL
# Create social app collections
curl -i -X PUT [INSTANCE-URL]/profiles -H "Authorization: Basic [BASIC-AUTH]"
curl -i -X PUT [INSTANCE-URL]/posts -H "Authorization: Basic [BASIC-AUTH]"
curl -i -X PUT [INSTANCE-URL]/followers -H "Authorization: Basic [BASIC-AUTH]"
# Create user profile
curl -i -X POST [INSTANCE-URL]/profiles \
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
-d '{
"username": "johndoe",
"displayName": "John Doe",
"email": "john@example.com",
"avatar": "https://example.com/avatars/john.jpg",
"bio": "Software developer and coffee enthusiast",
"location": "San Francisco, CA",
"joinedAt": "2024-01-01T00:00:00Z",
"stats": {
"posts": 0,
"followers": 0,
"following": 0
}
}'
# Create a post
curl -i -X POST [INSTANCE-URL]/posts \
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
-d '{
"author": "johndoe",
"content": "Just discovered RESTHeart Cloud - amazing for rapid API development! 🚀",
"media": [],
"hashtags": ["#api", "#development", "#restheart"],
"mentions": [],
"createdAt": "2024-01-15T14:30:00Z",
"likes": 0,
"comments": 0,
"shares": 0
}'
HTTPie
# Create social app collections
http PUT [INSTANCE-URL]/profiles Authorization:"Basic [BASIC-AUTH]"
http PUT [INSTANCE-URL]/posts Authorization:"Basic [BASIC-AUTH]"
http PUT [INSTANCE-URL]/followers Authorization:"Basic [BASIC-AUTH]"
# Create user profile
http POST [INSTANCE-URL]/profiles \
Authorization:"Basic [BASIC-AUTH]" \
Content-Type:application/json \
username="johndoe" \
displayName="John Doe" \
email="john@example.com" \
avatar="https://example.com/avatars/john.jpg" \
bio="Software developer and coffee enthusiast" \
location="San Francisco, CA" \
joinedAt="2024-01-01T00:00:00Z" \
stats:='{
"posts": 0,
"followers": 0,
"following": 0
}'
# Create a post
http POST [INSTANCE-URL]/posts \
Authorization:"Basic [BASIC-AUTH]" \
Content-Type:application/json \
author="johndoe" \
content="Just discovered RESTHeart Cloud - amazing for rapid API development! 🚀" \
media:='[]' \
hashtags:='["#api", "#development", "#restheart"]' \
mentions:='[]' \
createdAt="2024-01-15T14:30:00Z" \
likes:=0 \
comments:=0 \
shares:=0
JavaScript
// Create social app collections
const createSocialCollections = () => {
const headers = { 'Authorization': 'Basic [BASIC-AUTH]' };
fetch('[INSTANCE-URL]/profiles', { method: 'PUT', headers })
.then(response => {
if (response.ok) {
console.log('Profiles collection created successfully');
} else {
console.error('Failed to create profiles collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
fetch('[INSTANCE-URL]/posts', { method: 'PUT', headers })
.then(response => {
if (response.ok) {
console.log('Posts collection created successfully');
} else {
console.error('Failed to create posts collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
fetch('[INSTANCE-URL]/followers', { method: 'PUT', headers })
.then(response => {
if (response.ok) {
console.log('Followers collection created successfully');
} else {
console.error('Failed to create followers collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Create user profile
const createUserProfile = () => {
fetch('[INSTANCE-URL]/profiles', {
method: 'POST',
headers: {
'Authorization': 'Basic [BASIC-AUTH]',
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: "johndoe",
displayName: "John Doe",
email: "john@example.com",
avatar: "https://example.com/avatars/john.jpg",
bio: "Software developer and coffee enthusiast",
location: "San Francisco, CA",
joinedAt: "2024-01-01T00:00:00Z",
stats: {
posts: 0,
followers: 0,
following: 0
}
})
})
.then(response => {
if (response.ok) {
console.log('User profile created successfully');
} else {
console.error('Failed to create user profile:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Create a post
const createPost = () => {
fetch('[INSTANCE-URL]/posts', {
method: 'POST',
headers: {
'Authorization': 'Basic [BASIC-AUTH]',
'Content-Type': 'application/json'
},
body: JSON.stringify({
author: "johndoe",
content: "Just discovered RESTHeart Cloud - amazing for rapid API development! 🚀",
media: [],
hashtags: ["#api", "#development", "#restheart"],
mentions: [],
createdAt: "2024-01-15T14:30:00Z",
likes: 0,
comments: 0,
shares: 0
})
})
.then(response => {
if (response.ok) {
console.log('Post created successfully');
} else {
console.error('Failed to create post:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Execute
createSocialCollections();
createUserProfile();
createPost();
Social Features
cURL
# Get user timeline (posts from followed users)
curl "[INSTANCE-URL]/posts" --data-urlencode "filter={'author':{$in:['user1','user2','user3']}}" --data-urlencode "sort={createdAt:-1}"
# Search posts by hashtag
curl "[INSTANCE-URL]/posts" --data-urlencode "filter={'hashtags':{$in:['#api']}}"
# Get user's posts
curl "[INSTANCE-URL]/posts" --data-urlencode "filter={'author':'johndoe'}" --data-urlencode "sort={createdAt:-1}"
HTTPie
# Get user timeline (posts from followed users)
http GET [INSTANCE-URL]/posts filter=="{'author':{\$in:['user1','user2','user3']}}" sort=="{createdAt:-1}"
# Search posts by hashtag
http GET [INSTANCE-URL]/posts filter=="{'hashtags':{\$in:['#api']}}"
# Get user's posts
http GET [INSTANCE-URL]/posts filter=="{'author':'johndoe'}" sort=="{createdAt:-1}"
JavaScript
// Get user timeline (posts from followed users)
const getUserTimeline = (followedUsers) => {
const filter = encodeURIComponent(`{'author':{\$in:${JSON.stringify(followedUsers)}}}`);
const sort = encodeURIComponent("{createdAt:-1}");
fetch(`[INSTANCE-URL]/posts?filter=${filter}&sort=${sort}`)
.then(response => response.json())
.then(data => {
console.log('User timeline:', data);
})
.catch(error => console.error('Error:', error));
};
// Search posts by hashtag
const searchPostsByHashtag = (hashtag) => {
const filter = encodeURIComponent(`{'hashtags':{\$in:['${hashtag}']}}`);
fetch(`[INSTANCE-URL]/posts?filter=${filter}`)
.then(response => response.json())
.then(data => {
console.log('Hashtag search results:', data);
})
.catch(error => console.error('Error:', error));
};
// Get user's posts
const getUserPosts = (username) => {
const filter = encodeURIComponent(`{'author':'${username}'}`);
const sort = encodeURIComponent("{createdAt:-1}");
fetch(`[INSTANCE-URL]/posts?filter=${filter}&sort=${sort}`)
.then(response => response.json())
.then(data => {
console.log('User posts:', data);
})
.catch(error => console.error('Error:', error));
};
// Execute
getUserTimeline(['user1', 'user2', 'user3']);
searchPostsByHashtag('#api');
getUserPosts('johndoe');
Fitness Tracking App
Create a comprehensive fitness backend with workouts, progress tracking, and goals.
Workout Data
cURL
# Setup fitness collections
curl -i -X PUT [INSTANCE-URL]/workouts -H "Authorization: Basic [BASIC-AUTH]"
curl -i -X PUT [INSTANCE-URL]/exercises -H "Authorization: Basic [BASIC-AUTH]"
curl -i -X PUT [INSTANCE-URL]/progress -H "Authorization: Basic [BASIC-AUTH]"
# Add exercise definitions
curl -i -X POST [INSTANCE-URL]/exercises \
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
-d '{
"name": "Push-ups",
"category": "strength",
"muscleGroups": ["chest", "shoulders", "triceps"],
"equipment": "bodyweight",
"instructions": "Start in plank position, lower body until chest nearly touches floor, push back up",
"difficulty": "beginner"
}'
# Log workout
curl -i -X POST [INSTANCE-URL]/workouts \
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
-d '{
"userId": "user123",
"date": "2024-01-15T07:00:00Z",
"duration": 45,
"type": "strength",
"exercises": [
{
"name": "Push-ups",
"sets": [
{"reps": 15, "weight": 0},
{"reps": 12, "weight": 0},
{"reps": 10, "weight": 0}
]
}
],
"notes": "Great morning workout, feeling strong!",
"caloriesBurned": 200
}'
HTTPie
# Setup fitness collections
http PUT [INSTANCE-URL]/workouts Authorization:"Basic [BASIC-AUTH]"
http PUT [INSTANCE-URL]/exercises Authorization:"Basic [BASIC-AUTH]"
http PUT [INSTANCE-URL]/progress Authorization:"Basic [BASIC-AUTH]"
# Add exercise definitions
http POST [INSTANCE-URL]/exercises \
Authorization:"Basic [BASIC-AUTH]" \
Content-Type:application/json \
name="Push-ups" \
category="strength" \
muscleGroups:='["chest", "shoulders", "triceps"]' \
equipment="bodyweight" \
instructions="Start in plank position, lower body until chest nearly touches floor, push back up" \
difficulty="beginner"
# Log workout
http POST [INSTANCE-URL]/workouts \
Authorization:"Basic [BASIC-AUTH]" \
Content-Type:application/json \
userId="user123" \
date="2024-01-15T07:00:00Z" \
duration:=45 \
type="strength" \
exercises:='[
{
"name": "Push-ups",
"sets": [
{"reps": 15, "weight": 0},
{"reps": 12, "weight": 0},
{"reps": 10, "weight": 0}
]
}
]' \
notes="Great morning workout, feeling strong!" \
caloriesBurned:=200
JavaScript
// Setup fitness collections
const createFitnessCollections = () => {
const headers = { 'Authorization': 'Basic [BASIC-AUTH]' };
fetch('[INSTANCE-URL]/workouts', { method: 'PUT', headers })
.then(response => {
if (response.ok) {
console.log('Workouts collection created successfully');
} else {
console.error('Failed to create workouts collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
fetch('[INSTANCE-URL]/exercises', { method: 'PUT', headers })
.then(response => {
if (response.ok) {
console.log('Exercises collection created successfully');
} else {
console.error('Failed to create exercises collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
fetch('[INSTANCE-URL]/progress', { method: 'PUT', headers })
.then(response => {
if (response.ok) {
console.log('Progress collection created successfully');
} else {
console.error('Failed to create progress collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Add exercise definitions
const addExercise = () => {
fetch('[INSTANCE-URL]/exercises', {
method: 'POST',
headers: {
'Authorization': 'Basic [BASIC-AUTH]',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: "Push-ups",
category: "strength",
muscleGroups: ["chest", "shoulders", "triceps"],
equipment: "bodyweight",
instructions: "Start in plank position, lower body until chest nearly touches floor, push back up",
difficulty: "beginner"
})
})
.then(response => {
if (response.ok) {
console.log('Exercise added successfully');
} else {
console.error('Failed to add exercise:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Log workout
const logWorkout = () => {
fetch('[INSTANCE-URL]/workouts', {
method: 'POST',
headers: {
'Authorization': 'Basic [BASIC-AUTH]',
'Content-Type': 'application/json'
},
body: JSON.stringify({
userId: "user123",
date: "2024-01-15T07:00:00Z",
duration: 45,
type: "strength",
exercises: [
{
name: "Push-ups",
sets: [
{reps: 15, weight: 0},
{reps: 12, weight: 0},
{reps: 10, weight: 0}
]
}
],
notes: "Great morning workout, feeling strong!",
caloriesBurned: 200
})
})
.then(response => {
if (response.ok) {
console.log('Workout logged successfully');
} else {
console.error('Failed to log workout:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Execute
createFitnessCollections();
addExercise();
logWorkout();
IoT and Data Collection
Smart Home Monitoring
Collect and analyze data from home sensors and devices.
Sensor Data Collection
cURL
# Create IoT collections
curl -i -X PUT [INSTANCE-URL]/devices -H "Authorization: Basic [BASIC-AUTH]"
curl -i -X PUT [INSTANCE-URL]/readings -H "Authorization: Basic [BASIC-AUTH]"
curl -i -X PUT [INSTANCE-URL]/alerts -H "Authorization: Basic [BASIC-AUTH]"
# Register device
curl -i -X POST [INSTANCE-URL]/devices \
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
-d '{
"deviceId": "temp-sensor-01",
"type": "temperature",
"location": "living-room",
"manufacturer": "SensorTech",
"model": "ST-TEMP-100",
"installDate": "2024-01-01T00:00:00Z",
"status": "active"
}'
# Submit sensor reading
curl -i -X POST [INSTANCE-URL]/readings \
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
-d '{
"deviceId": "temp-sensor-01",
"timestamp": "2024-01-15T15:30:00Z",
"measurements": {
"temperature": 22.5,
"humidity": 45.2,
"batteryLevel": 85
},
"location": "living-room"
}'
HTTPie
# Create IoT collections
http PUT [INSTANCE-URL]/devices Authorization:"Basic [BASIC-AUTH]"
http PUT [INSTANCE-URL]/readings Authorization:"Basic [BASIC-AUTH]"
http PUT [INSTANCE-URL]/alerts Authorization:"Basic [BASIC-AUTH]"
# Register device
http POST [INSTANCE-URL]/devices \
Authorization:"Basic [BASIC-AUTH]" \
Content-Type:application/json \
deviceId="temp-sensor-01" \
type="temperature" \
location="living-room" \
manufacturer="SensorTech" \
model="ST-TEMP-100" \
installDate="2024-01-01T00:00:00Z" \
status="active"
# Submit sensor reading
http POST [INSTANCE-URL]/readings \
Authorization:"Basic [BASIC-AUTH]" \
Content-Type:application/json \
deviceId="temp-sensor-01" \
timestamp="2024-01-15T15:30:00Z" \
measurements:='{
"temperature": 22.5,
"humidity": 45.2,
"batteryLevel": 85
}' \
location="living-room"
JavaScript
// Create IoT collections
const createIoTCollections = () => {
const headers = { 'Authorization': 'Basic [BASIC-AUTH]' };
fetch('[INSTANCE-URL]/devices', { method: 'PUT', headers })
.then(response => {
if (response.ok) {
console.log('Devices collection created successfully');
} else {
console.error('Failed to create devices collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
fetch('[INSTANCE-URL]/readings', { method: 'PUT', headers })
.then(response => {
if (response.ok) {
console.log('Readings collection created successfully');
} else {
console.error('Failed to create readings collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
fetch('[INSTANCE-URL]/alerts', { method: 'PUT', headers })
.then(response => {
if (response.ok) {
console.log('Alerts collection created successfully');
} else {
console.error('Failed to create alerts collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Register device
const registerDevice = () => {
fetch('[INSTANCE-URL]/devices', {
method: 'POST',
headers: {
'Authorization': 'Basic [BASIC-AUTH]',
'Content-Type': 'application/json'
},
body: JSON.stringify({
deviceId: "temp-sensor-01",
type: "temperature",
location: "living-room",
manufacturer: "SensorTech",
model: "ST-TEMP-100",
installDate: "2024-01-01T00:00:00Z",
status: "active"
})
})
.then(response => {
if (response.ok) {
console.log('Device registered successfully');
} else {
console.error('Failed to register device:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Submit sensor reading
const submitReading = () => {
fetch('[INSTANCE-URL]/readings', {
method: 'POST',
headers: {
'Authorization': 'Basic [BASIC-AUTH]',
'Content-Type': 'application/json'
},
body: JSON.stringify({
deviceId: "temp-sensor-01",
timestamp: "2024-01-15T15:30:00Z",
measurements: {
temperature: 22.5,
humidity: 45.2,
batteryLevel: 85
},
location: "living-room"
})
})
.then(response => {
if (response.ok) {
console.log('Sensor reading submitted successfully');
} else {
console.error('Failed to submit sensor reading:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Execute
createIoTCollections();
registerDevice();
submitReading();
Data Analysis
cURL
# Get recent readings
curl -i "[INSTANCE-URL]/readings" --data-urlencode "filter={'timestamp':{$gte:'2024-01-15T00:00:00Z'}}" --data-urlencode "sort={timestamp:-1}"
# Average temperature by location
curl -i -X POST [INSTANCE-URL]/readings/_aggrs/avg-temp-by-location \
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
-d '[
{"$match": {"timestamp": {"$gte": "2024-01-15T00:00:00Z"}}},
{"$group": {
"_id": "$location",
"avgTemp": {"$avg": "$measurements.temperature"},
"count": {"$sum": 1}
}}
]'
HTTPie
# Get recent readings
http GET [INSTANCE-URL]/readings filter=="{'timestamp':{\$gte:'2024-01-15T00:00:00Z'}}" sort=="{timestamp:-1}"
# Average temperature by location
echo '[
{"$match": {"timestamp": {"$gte": "2024-01-15T00:00:00Z"}}},
{"$group": {
"_id": "$location",
"avgTemp": {"$avg": "$measurements.temperature"},
"count": {"$sum": 1}
}}
]' | http POST [INSTANCE-URL]/readings/_aggrs/avg-temp-by-location \
Authorization:"Basic [BASIC-AUTH]" \
Content-Type:application/json
JavaScript
// Get recent readings
const getRecentReadings = () => {
const filter = encodeURIComponent("{'timestamp':{\$gte:'2024-01-15T00:00:00Z'}}");
const sort = encodeURIComponent("{timestamp:-1}");
fetch(`[INSTANCE-URL]/readings?filter=${filter}&sort=${sort}`)
.then(response => response.json())
.then(data => {
console.log('Recent readings:', data);
})
.catch(error => console.error('Error:', error));
};
// Average temperature by location
const getAverageTemperatureByLocation = () => {
const pipeline = [
{"$match": {"timestamp": {"$gte": "2024-01-15T00:00:00Z"}}},
{"$group": {
"_id": "$location",
"avgTemp": {"$avg": "$measurements.temperature"},
"count": {"$sum": 1}
}}
];
fetch('[INSTANCE-URL]/readings/_aggrs/avg-temp-by-location', {
method: 'POST',
headers: {
'Authorization': 'Basic [BASIC-AUTH]',
'Content-Type': 'application/json'
},
body: JSON.stringify(pipeline)
})
.then(response => response.json())
.then(data => {
console.log('Average temperature by location:', data);
})
.catch(error => console.error('Error:', error));
};
// Execute
getRecentReadings();
getAverageTemperatureByLocation();
Environmental Monitoring
Track air quality, weather conditions, and environmental data.
Environmental Data
cURL
# Environmental monitoring setup
curl -i -X PUT [INSTANCE-URL]/stations -H "Authorization: Basic [BASIC-AUTH]"
curl -i -X PUT [INSTANCE-URL]/measurements -H "Authorization: Basic [BASIC-AUTH]"
# Register monitoring station
curl -i -X POST [INSTANCE-URL]/stations \
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
-d '{
"stationId": "ENV-NYC-001",
"name": "Central Park Station",
"location": {
"lat": 40.7829,
"lng": -73.9654,
"address": "Central Park, New York, NY"
},
"sensors": ["PM2.5", "PM10", "NO2", "O3", "temperature", "humidity"],
"status": "active"
}'
# Submit environmental measurement
curl -i -X POST [INSTANCE-URL]/measurements \
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
-d '{
"stationId": "ENV-NYC-001",
"timestamp": "2024-01-15T16:00:00Z",
"airQuality": {
"pm25": 12.5,
"pm10": 18.2,
"no2": 25.1,
"o3": 45.8,
"aqi": 52
},
"weather": {
"temperature": 18.5,
"humidity": 62.3,
"pressure": 1013.2,
"windSpeed": 8.5
}
}'
HTTPie
# Environmental monitoring setup
http PUT [INSTANCE-URL]/stations Authorization:"Basic [BASIC-AUTH]"
http PUT [INSTANCE-URL]/measurements Authorization:"Basic [BASIC-AUTH]"
# Register monitoring station
http POST [INSTANCE-URL]/stations \
Authorization:"Basic [BASIC-AUTH]" \
Content-Type:application/json \
stationId="ENV-NYC-001" \
name="Central Park Station" \
location:='{
"lat": 40.7829,
"lng": -73.9654,
"address": "Central Park, New York, NY"
}' \
sensors:='["PM2.5", "PM10", "NO2", "O3", "temperature", "humidity"]' \
status="active"
# Submit environmental measurement
http POST [INSTANCE-URL]/measurements \
Authorization:"Basic [BASIC-AUTH]" \
Content-Type:application/json \
stationId="ENV-NYC-001" \
timestamp="2024-01-15T16:00:00Z" \
airQuality:='{
"pm25": 12.5,
"pm10": 18.2,
"no2": 25.1,
"o3": 45.8,
"aqi": 52
}' \
weather:='{
"temperature": 18.5,
"humidity": 62.3,
"pressure": 1013.2,
"windSpeed": 8.5
}'
JavaScript
// Environmental monitoring setup
const createEnvironmentalCollections = () => {
const headers = { 'Authorization': 'Basic [BASIC-AUTH]' };
fetch('[INSTANCE-URL]/stations', { method: 'PUT', headers })
.then(response => {
if (response.ok) {
console.log('Stations collection created successfully');
} else {
console.error('Failed to create stations collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
fetch('[INSTANCE-URL]/measurements', { method: 'PUT', headers })
.then(response => {
if (response.ok) {
console.log('Measurements collection created successfully');
} else {
console.error('Failed to create measurements collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Register monitoring station
const registerStation = () => {
fetch('[INSTANCE-URL]/stations', {
method: 'POST',
headers: {
'Authorization': 'Basic [BASIC-AUTH]',
'Content-Type': 'application/json'
},
body: JSON.stringify({
stationId: "ENV-NYC-001",
name: "Central Park Station",
location: {
lat: 40.7829,
lng: -73.9654,
address: "Central Park, New York, NY"
},
sensors: ["PM2.5", "PM10", "NO2", "O3", "temperature", "humidity"],
status: "active"
})
})
.then(response => {
if (response.ok) {
console.log('Environmental monitoring station registered successfully');
} else {
console.error('Failed to register monitoring station:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Submit environmental measurement
const submitMeasurement = () => {
fetch('[INSTANCE-URL]/measurements', {
method: 'POST',
headers: {
'Authorization': 'Basic [BASIC-AUTH]',
'Content-Type': 'application/json'
},
body: JSON.stringify({
stationId: "ENV-NYC-001",
timestamp: "2024-01-15T16:00:00Z",
airQuality: {
pm25: 12.5,
pm10: 18.2,
no2: 25.1,
o3: 45.8,
aqi: 52
},
weather: {
temperature: 18.5,
humidity: 62.3,
pressure: 1013.2,
windSpeed: 8.5
}
})
})
.then(response => {
if (response.ok) {
console.log('Environmental measurement submitted successfully');
} else {
console.error('Failed to submit environmental measurement:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Execute
createEnvironmentalCollections();
registerStation();
submitMeasurement();
Analytics and Reporting
Business Intelligence Dashboard
Create a comprehensive analytics backend for business metrics.
Sales Analytics
cURL
# Business analytics setup
curl -i -X PUT [INSTANCE-URL]/sales -H "Authorization: Basic [BASIC-AUTH]"
curl -i -X PUT [INSTANCE-URL]/customers -H "Authorization: Basic [BASIC-AUTH]"
curl -i -X PUT [INSTANCE-URL]/analytics-products -H "Authorization: Basic [BASIC-AUTH]"
# Record sale
curl -i -X POST [INSTANCE-URL]/sales \
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
-d '{
"orderId": "ORD-2024-001",
"customerId": "CUST-001",
"date": "2024-01-15T14:30:00Z",
"items": [
{
"productId": "PROD-001",
"name": "Wireless Headphones",
"quantity": 1,
"unitPrice": 99.99,
"category": "electronics"
}
],
"totalAmount": 99.99,
"currency": "USD",
"paymentMethod": "credit_card",
"salesRep": "john.doe@company.com",
"region": "north-america"
}'
HTTPie
# Business analytics setup
http PUT [INSTANCE-URL]/sales Authorization:"Basic [BASIC-AUTH]"
http PUT [INSTANCE-URL]/customers Authorization:"Basic [BASIC-AUTH]"
http PUT [INSTANCE-URL]/analytics-products Authorization:"Basic [BASIC-AUTH]"
# Record sale
http POST [INSTANCE-URL]/sales \
Authorization:"Basic [BASIC-AUTH]" \
Content-Type:application/json \
orderId="ORD-2024-001" \
customerId="CUST-001" \
date="2024-01-15T14:30:00Z" \
items:='[
{
"productId": "PROD-001",
"name": "Wireless Headphones",
"quantity": 1,
"unitPrice": 99.99,
"category": "electronics"
}
]' \
totalAmount:=99.99 \
currency="USD" \
paymentMethod="credit_card" \
salesRep="john.doe@company.com" \
region="north-america"
JavaScript
// Business analytics setup
const createAnalyticsCollections = () => {
const headers = { 'Authorization': 'Basic [BASIC-AUTH]' };
fetch('[INSTANCE-URL]/sales', { method: 'PUT', headers })
.then(response => {
if (response.ok) {
console.log('Sales collection created successfully');
} else {
console.error('Failed to create sales collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
fetch('[INSTANCE-URL]/customers', { method: 'PUT', headers })
.then(response => {
if (response.ok) {
console.log('Customers collection created successfully');
} else {
console.error('Failed to create customers collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
fetch('[INSTANCE-URL]/analytics-products', { method: 'PUT', headers })
.then(response => {
if (response.ok) {
console.log('Analytics products collection created successfully');
} else {
console.error('Failed to create analytics products collection:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Record sale
const recordSale = () => {
fetch('[INSTANCE-URL]/sales', {
method: 'POST',
headers: {
'Authorization': 'Basic [BASIC-AUTH]',
'Content-Type': 'application/json'
},
body: JSON.stringify({
orderId: "ORD-2024-001",
customerId: "CUST-001",
date: "2024-01-15T14:30:00Z",
items: [
{
productId: "PROD-001",
name: "Wireless Headphones",
quantity: 1,
unitPrice: 99.99,
category: "electronics"
}
],
totalAmount: 99.99,
currency: "USD",
paymentMethod: "credit_card",
salesRep: "john.doe@company.com",
region: "north-america"
})
})
.then(response => {
if (response.ok) {
console.log('Sale recorded successfully');
} else {
console.error('Failed to record sale:', response.status);
}
})
.catch(error => console.error('Error:', error));
};
// Execute
createAnalyticsCollections();
recordSale();
Analytics Queries
cURL
# Daily sales aggregation
curl -i -X POST [INSTANCE-URL]/sales/_aggrs/daily-sales \
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
-d '[
{"$match": {"date": {"$gte": "2024-01-01T00:00:00Z"}}},
{"$group": {
"_id": {"$dateToString": {"format": "%Y-%m-%d", "date": "$date"}},
"totalSales": {"$sum": "$totalAmount"},
"orderCount": {"$sum": 1},
"avgOrderValue": {"$avg": "$totalAmount"}
}},
{"$sort": {"_id": 1}}
]'
# Top products by revenue
curl -i -X POST [INSTANCE-URL]/sales/_aggrs/top-products \
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
-d '[
{"$unwind": "$items"},
{"$group": {
"_id": "$items.productId",
"productName": {"$first": "$items.name"},
"totalRevenue": {"$sum": {"$multiply": ["$items.quantity", "$items.unitPrice"]}},
"unitsSold": {"$sum": "$items.quantity"}
}},
{"$sort": {"totalRevenue": -1}},
{"$limit": 10}
]'
HTTPie
# Daily sales aggregation
echo '[
{"$match": {"date": {"$gte": "2024-01-01T00:00:00Z"}}},
{"$group": {
"_id": {"$dateToString": {"format": "%Y-%m-%d", "date": "$date"}},
"totalSales": {"$sum": "$totalAmount"},
"orderCount": {"$sum": 1},
"avgOrderValue": {"$avg": "$totalAmount"}
}},
{"$sort": {"_id": 1}}
]' | http POST [INSTANCE-URL]/sales/_aggrs/daily-sales \
Authorization:"Basic [BASIC-AUTH]" \
Content-Type:application/json
# Top products by revenue
echo '[
{"$unwind": "$items"},
{"$group": {
"_id": "$items.productId",
"productName": {"$first": "$items.name"},
"totalRevenue": {"$sum": {"$multiply": ["$items.quantity", "$items.unitPrice"]}},
"unitsSold": {"$sum": "$items.quantity"}
}},
{"$sort": {"totalRevenue": -1}},
{"$limit": 10}
]' | http POST [INSTANCE-URL]/sales/_aggrs/top-products \
Authorization:"Basic [BASIC-AUTH]" \
Content-Type:application/json
JavaScript
// Daily sales aggregation
const getDailySales = () => {
const pipeline = [
{"$match": {"date": {"$gte": "2024-01-01T00:00:00Z"}}},
{"$group": {
"_id": {"$dateToString": {"format": "%Y-%m-%d", "date": "$date"}},
"totalSales": {"$sum": "$totalAmount"},
"orderCount": {"$sum": 1},
"avgOrderValue": {"$avg": "$totalAmount"}
}},
{"$sort": {"_id": 1}}
];
fetch('[INSTANCE-URL]/sales/_aggrs/daily-sales', {
method: 'POST',
headers: {
'Authorization': 'Basic [BASIC-AUTH]',
'Content-Type': 'application/json'
},
body: JSON.stringify(pipeline)
})
.then(response => response.json())
.then(data => {
console.log('Daily sales data:', data);
})
.catch(error => console.error('Error:', error));
};
// Top products by revenue
const getTopProducts = () => {
const pipeline = [
{"$unwind": "$items"},
{"$group": {
"_id": "$items.productId",
"productName": {"$first": "$items.name"},
"totalRevenue": {"$sum": {"$multiply": ["$items.quantity", "$items.unitPrice"]}},
"unitsSold": {"$sum": "$items.quantity"}
}},
{"$sort": {"totalRevenue": -1}},
{"$limit": 10}
];
fetch('[INSTANCE-URL]/sales/_aggrs/top-products', {
method: 'POST',
headers: {
'Authorization': 'Basic [BASIC-AUTH]',
'Content-Type': 'application/json'
},
body: JSON.stringify(pipeline)
})
.then(response => response.json())
.then(data => {
console.log('Top products data:', data);
})
.catch(error => console.error('Error:', error));
};
// Execute
getDailySales();
getTopProducts();
Real-Time Applications
Live Chat System
Build a real-time messaging platform with presence and typing indicators.
Chat Setup
# Chat collections
curl -i -X PUT https://[instance].restheart.com/rooms -H "Authorization: Bearer [token]"
curl -i -X PUT https://[instance].restheart.com/messages -H "Authorization: Bearer [token]"
curl -i -X PUT https://[instance].restheart.com/presence -H "Authorization: Bearer [token]"
# Create chat room
curl -i -X POST https://[instance].restheart.com/rooms \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"name": "General Discussion",
"description": "General chat for all team members",
"type": "public",
"createdBy": "admin",
"createdAt": "2024-01-15T10:00:00Z",
"members": ["alice", "bob", "charlie"],
"settings": {
"allowFileSharing": true,
"maxMessageLength": 1000
}
}'
# Send message
curl -i -X POST https://[instance].restheart.com/messages \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"roomId": "general-discussion",
"sender": "alice",
"content": "Hello everyone! 👋",
"type": "text",
"timestamp": "2024-01-15T15:30:00Z",
"edited": false,
"reactions": []
}'
Real-time Features with WebSockets
# Create change stream for real-time messages
curl -i -X POST https://[instance].restheart.com/_streams/chat-messages \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"uri": "chat-messages",
"stages": [
{"$match": {"ns.coll": "messages"}},
{"$project": {"_id": 1, "operationType": 1, "fullDocument": 1}}
]
}'
# WebSocket connection for real-time updates
# ws://[instance].restheart.com/_streams/chat-messages
Live Polling and Voting
Create real-time polls and surveys with live result updates.
Polling System
# Polling collections
curl -i -X PUT https://[instance].restheart.com/questions -H "Authorization: Bearer [token]"
curl -i -X PUT https://[instance].restheart.com/votes -H "Authorization: Bearer [token]"
# Create poll
curl -i -X POST https://[instance].restheart.com/questions \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"title": "What is your favorite programming language?",
"description": "Help us understand our community preferences",
"options": [
{"id": "js", "text": "JavaScript", "votes": 0},
{"id": "python", "text": "Python", "votes": 0},
{"id": "java", "text": "Java", "votes": 0},
{"id": "go", "text": "Go", "votes": 0}
],
"createdBy": "admin",
"createdAt": "2024-01-15T10:00:00Z",
"endDate": "2024-01-22T23:59:59Z",
"status": "active",
"allowMultiple": false
}'
# Cast vote
curl -i -X POST https://[instance].restheart.com/votes \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"pollId": "programming-languages-poll",
"userId": "user123",
"selectedOption": "python",
"timestamp": "2024-01-15T15:45:00Z",
"userAgent": "Mozilla/5.0...",
"ipAddress": "192.168.1.100"
}'
Public Data Access
Open Data APIs
Create public APIs that don’t require authentication, perfect for open datasets, public content, or read-only resources.
Setting Up Public Collections
Configure collections to allow access via the $unauthenticated
role for users who haven’t logged in.
# Create public collections for open data
curl -i -X PUT https://[instance].restheart.com/public-datasets -H "Authorization: Bearer [token]"
curl -i -X PUT https://[instance].restheart.com/announcements -H "Authorization: Bearer [token]"
curl -i -X PUT https://[instance].restheart.com/documentation -H "Authorization: Bearer [token]"
# Configure public read access permissions
curl -i -X PUT https://[instance].restheart.com/acl \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"role": "$unauthenticated",
"predicate": "method(GET) and path-prefix(/public-datasets)"
}
}'
Public Content Examples
# Add public announcements (admin-only write, public read)
curl -i -X POST https://[instance].restheart.com/announcements \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"title": "Platform Maintenance Scheduled",
"message": "We will be performing routine maintenance on January 20th from 2-4 AM UTC.",
"type": "maintenance",
"severity": "info",
"publishedAt": "2024-01-15T10:00:00Z",
"expiresAt": "2024-01-21T00:00:00Z",
"tags": ["maintenance", "scheduled"]
}'
# Add public dataset entry
curl -i -X POST https://[instance].restheart.com/public-datasets \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"name": "City Weather Stations",
"description": "Real-time weather data from municipal weather monitoring stations",
"category": "environmental",
"format": "JSON",
"updateFrequency": "hourly",
"license": "Creative Commons Attribution 4.0",
"lastUpdated": "2024-01-15T16:00:00Z",
"recordCount": 1250,
"coverage": {
"geographic": "New York City",
"temporal": "2020-present"
},
"contact": "data@city.gov"
}'
Public API Access (No Authentication Required)
# Anyone can access these endpoints without authentication
# Get all public announcements
curl "https://[instance].restheart.com/announcements"
# Get active announcements
curl "https://[instance].restheart.com/announcements" --data-urlencode "filter={'expiresAt':{$gte:'2024-01-15T00:00:00Z'}}"
# Browse public datasets
curl "https://[instance].restheart.com/public-datasets"
# Search datasets by category
curl "https://[instance].restheart.com/public-datasets" --data-urlencode "filter={'category':'environmental'}"
# Get specific dataset information
curl "https://[instance].restheart.com/public-datasets/city-weather-stations"
Public Documentation Portal
Create a knowledge base or documentation system with public read access and controlled write access.
Documentation Setup
# Create documentation collections
curl -i -X PUT https://[instance].restheart.com/docs -H "Authorization: Bearer [token]"
curl -i -X PUT https://[instance].restheart.com/faqs -H "Authorization: Bearer [token]"
# Configure public read access for documentation
curl -i -X PUT https://[instance].restheart.com/acl \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"role": "$unauthenticated",
"predicate": "method(GET) and path-prefix(/docs)",
"mongo": {
"readFilter": {"status": "published"}
}
}'
# Configure editor write access for documentation
curl -i -X PUT https://[instance].restheart.com/acl \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"role": "editor",
"predicate": "(method(GET) or method(POST) or method(PATCH)) and path-prefix(/docs)",
"mongo": {
"mergeRequest": { "author": "@user._id" },
"writeFilter": { "author": "@user._id" }
}
}'
# Add documentation articles
curl -i -X POST https://[instance].restheart.com/docs \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"title": "Getting Started Guide",
"slug": "getting-started",
"content": "This comprehensive guide will help you get started with our platform...",
"category": "tutorials",
"status": "published",
"publishedAt": "2024-01-15T10:00:00Z",
"lastModified": "2024-01-15T10:00:00Z",
"author": "docs-team",
"tags": ["beginner", "tutorial", "setup"],
"version": "1.0"
}'
Public FAQ System
# Configure FAQ collection for public access
curl -i -X PUT https://[instance].restheart.com/acl \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"role": "$unauthenticated",
"predicate": "method(GET) and path-prefix(/faqs)"
}'
# Add FAQ entries
curl -i -X POST https://[instance].restheart.com/faqs \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"question": "How do I reset my password?",
"answer": "Click on the Forgot Password link on the login page and follow the instructions sent to your email.",
"category": "account",
"tags": ["password", "login", "account"],
"helpful": 0,
"notHelpful": 0,
"lastUpdated": "2024-01-15T10:00:00Z"
}'
Public Event Calendar
Create a public events system where anyone can view upcoming events.
Event Calendar Setup
# Create events collection
curl -i -X PUT https://[instance].restheart.com/events -H "Authorization: Bearer [token]"
# Configure public read access for future events only
curl -i -X PUT https://[instance].restheart.com/acl \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"role": "$unauthenticated",
"predicate": "method(GET) and path-prefix(/events)",
"mongo": {
"readFilter": {
"status": "published",
"endDate": {"$gte": {"$date": "2024-01-15T00:00:00Z"}}
}
}
}'
# Add public events
curl -i -X POST https://[instance].restheart.com/events \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"title": "API Workshop: Building with RESTHeart",
"description": "Learn how to build powerful APIs using RESTHeart Cloud",
"startDate": "2024-01-25T14:00:00Z",
"endDate": "2024-01-25T16:00:00Z",
"location": {
"type": "online",
"url": "https://meet.example.com/workshop"
},
"status": "published",
"category": "workshop",
"maxAttendees": 50,
"currentAttendees": 12,
"tags": ["api", "workshop", "development"],
"organizer": "Developer Relations Team"
}'
Public Access Examples
# Public users can access these without authentication
# Get upcoming events
curl "https://[instance].restheart.com/events" --data-urlencode "sort={startDate:1}"
# Filter events by category
curl "https://[instance].restheart.com/events" --data-urlencode "filter={'category':'workshop'}"
# Get events for a specific date range
curl "https://[instance].restheart.com/events" --data-urlencode "filter={'startDate':{$gte:'2024-01-20T00:00:00Z',$lt:'2024-01-27T00:00:00Z'}}"
Security Considerations for Public Access
# Best practices for public collections:
# 1. Use specific read filters to limit exposed data
# 2. Never allow write access for $unauthenticated role
# Example: Limit fields exposed to public users
curl -i -X PUT https://[instance].restheart.com/acl \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"role": "$unauthenticated",
"predicate": "method(GET) and path('/events')",
"mongo": {
"readFilter": {"public": true},
"projectResponse": {
"username": 1,
"displayName": 1,
"avatar": 1,
"joinedAt": 1
}
}
}'
Advanced Integration Examples
Multi-tenant SaaS Application
Build a SaaS platform with proper tenant isolation and billing.
Tenant Management
# SaaS collections
curl -i -X PUT https://[instance].restheart.com/tenants -H "Authorization: Bearer [token]"
curl -i -X PUT https://[instance].restheart.com/subscriptions -H "Authorization: Bearer [token]"
curl -i -X PUT https://[instance].restheart.com/usage -H "Authorization: Bearer [token]"
# Create tenant
curl -i -X POST https://[instance].restheart.com/tenants \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"tenantId": "acme-corp",
"name": "ACME Corporation",
"plan": "professional",
"status": "active",
"createdAt": "2024-01-15T10:00:00Z",
"settings": {
"maxUsers": 50,
"maxStorage": "10GB",
"features": ["analytics", "integrations", "priority-support"]
},
"billing": {
"email": "billing@acme.com",
"address": "123 Business St, City, State 12345"
}
}'
Usage Tracking
# Track API usage
curl -i -X POST https://[instance].restheart.com/usage \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"tenantId": "acme-corp",
"date": "2024-01-15",
"metrics": {
"apiCalls": 1250,
"storageUsed": "2.5GB",
"activeUsers": 23,
"dataTransfer": "150MB"
},
"breakdown": {
"endpoints": {
"/api/users": 450,
"/api/projects": 320,
"/api/tasks": 480
}
}
}'
Performance and Optimization
Caching Strategy
# Enable caching for frequently accessed data
curl -i -X PUT https://[instance].restheart.com/products \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"cachePolicy": {
"enabled": true,
"ttl": 300,
"invalidateOn": ["POST", "PUT", "PATCH", "DELETE"]
}
}'
Indexing for Performance
# Create indexes for better query performance
curl -i -X PUT https://[instance].restheart.com/products/_indexes/category-price \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"keys": {"category": 1, "price": -1},
"options": {"name": "category_price_idx"}
}'
# Text index for search
curl -i -X PUT https://[instance].restheart.com/products/_indexes/text-search \
-H "Authorization: Bearer [token]" -H "Content-Type: application/json" \
-d '{
"keys": {"name": "text", "description": "text", "tags": "text"},
"options": {"name": "product_text_search"}
}'
Next Steps
These examples demonstrate the power and flexibility of RESTHeart Cloud across different domains. To implement any of these solutions:
-
Start with the Free tier to experiment and prototype
-
Adapt the data models to fit your specific requirements
-
Implement proper security with user roles and permissions
-
Add real-time features using WebSocket change streams
-
Scale up to Shared or Dedicated tiers as your application grows
Learn More
-
Getting Started Guide - Build your first API
-
User Management - Advanced authentication and authorization
-
Security Best Practices - Production-ready security
-
Data Aggregations - Advanced analytics and reporting
-
Authentication Mechanisms - Configure public access with
$unauthenticated
role
Ready to build your next application? Sign up at https://cloud.restheart.com and get your backend running in minutes! 🚀