Quick Start
Get up and running with Synap SDK in under 5 minutes.
💡 Want an even faster start? Check out our starter templates with pre-configured SDK, UI components, and authentication.
Initialize the SDK
import { SynapSDK } from '@synap/sdk'
const synap = new SynapSDK({
url: 'http://localhost:3000', // or 'https://api.synap.app'
apiKey: 'your-api-key'
})Create Your First Entity
// Create a task
const { entityId } = await synap.entities.create({
type: 'task',
title: 'Build amazing app',
metadata: {
priority: 'high',
dueDate: '2024-12-25'
}
})
console.log('Created task:', entityId)Query Entities
// List all tasks
const tasks = await synap.entities.list({
type: 'task',
limit: 10
})
console.log('Tasks:', tasks)Create a Relationship
// Create a person
const { entityId: personId } = await synap.entities.create({
type: 'person',
title: 'Marie Johnson',
metadata: {
email: 'marie@example.com'
}
})
// Assign task to person
await synap.relations.create(
entityId,
personId,
'assigned_to'
)
console.log('Task assigned to Marie!')View Event History
// Get complete history for the task
const history = await synap.events.getHistory(entityId)
console.log('Event timeline:', history)Complete Example
Here’s a complete working example:
app.ts
import { SynapSDK } from '@synap/sdk'
const synap = new SynapSDK({
url: 'http://localhost:3000',
apiKey: process.env.SYNAP_API_KEY!
})
async function main() {
// 1. Create task
const { entityId: taskId } = await synap.entities.create({
type: 'task',
title: 'Call Marie',
metadata: { priority: 'high' }
})
// 2. Create person
const { entityId: personId } = await synap.entities.create({
type: 'person',
title: 'Marie Johnson',
metadata: { email: 'marie@example.com' }
})
// 3. Create relationship
await synap.relations.create(taskId, personId, 'assigned_to')
// 4. Query related entities
const assignees = await synap.relations.getRelated(taskId, {
type: 'assigned_to'
})
console.log('Task assigned to:', assignees[0]?.title)
// 5. Update task
await synap.entities.update(taskId, {
metadata: { status: 'done', completedAt: new Date() }
})
// 6. View history
const history = await synap.events.getHistory(taskId)
console.log(`Task has ${history.length} events`)
}
main().catch(console.error)What’s Happening?
Event Sourcing
Every create, update, and delete operation is logged as an event:
synap.entities.create()
→ events.log('entities.create.requested')
→ Inngest worker processes event
→ Database updated
→ Validation event emittedDirect Reads
Query operations hit the database directly for speed:
synap.entities.list()
→ Direct database query
→ Returns results immediatelyNext Steps
- Authentication → - Configure API keys properly
- Core Concepts → - Understand event sourcing
- API Reference → - Explore all methods
- Deploy Your App → - Production deployment guide
Last updated on