REST API Examples
This document provides examples for using the ChronDB REST API with curl and JavaScript.
REST API Overview
ChronDB provides a RESTful API that allows you to interact with the database over HTTP. This makes it easy to integrate with any programming language or environment that can make HTTP requests.
The REST API server can be configured in the config.edn file:
:servers {
:rest {
:enabled true
:host "0.0.0.0"
:port 3000
}
}Examples with curl
Document Operations
Create or Update a Document
# Create a new document
curl -X POST http://localhost:3000/api/v1/documents/user:1 \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "[email protected]",
"age": 30,
"roles": ["admin", "user"]
}'
# Response
# {"status":"success","key":"user:1"}Get a Document
Delete a Document
Search Operations
Version Control Operations
Get Document History
Get Document at a Point in Time
Compare Document Versions
Branch Operations
List Branches
Create a Branch
Switch Branch
Merge Branches
Examples with JavaScript
Setting Up
Document Operations
Search Operations
Version Control Operations
Branch Operations
Complete Example: User Management System
Schema Validation Operations
ChronDB supports optional JSON Schema validation per namespace. See the Schema Validation documentation for full details.
Managing Validation Schemas
Create a Validation Schema
List All Validation Schemas
Get a Specific Schema
Get Schema History
Delete a Validation Schema
Dry-Run Validation
Test if a document is valid before saving:
Validation Error Response
When saving a document that fails validation in strict mode:
JavaScript Validation Examples
Last updated
Was this helpful?