Build a REST API
Create a full CRUD REST API using zMesh's Auto API — no code needed. Just create tables and get instant REST + GraphQL endpoints.
1. Create Your Tables
CLI or Dashboard
zmesh database query "
CREATE TABLE posts (
id SERIAL PRIMARY KEY,
title TEXT NOT NULL,
body TEXT,
author TEXT,
published BOOLEAN DEFAULT false,
created_at TIMESTAMP DEFAULT NOW()
)"2. Use the Auto API
zMesh automatically generates REST endpoints for every table. No configuration needed.
| Operation | Endpoint | Method |
|---|---|---|
| List all | /api/data/posts | GET |
| Get one | /api/data/posts/1 | GET |
| Create | /api/data/posts | POST |
| Update | /api/data/posts/1 | PATCH |
| Delete | /api/data/posts/1 | DELETE |
3. Call from Your App
Create a postAPI Key
curl -X POST https://api.zmesh.in/api/data/posts \
-H "x-api-key: zb_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"title": "Hello World",
"body": "My first post",
"author": "Alice"
}'List posts with filters
# Pagination
GET /api/data/posts?limit=10&offset=0
# Filter
GET /api/data/posts?published=true
# Sort
GET /api/data/posts?order=created_at.desc
# Select fields
GET /api/data/posts?select=id,title,author4. Add RLS (Optional)
Secure your API with Row-Level Security so users only see their own data:
-- Enable RLS on the table
ALTER TABLE posts ENABLE ROW LEVEL SECURITY;
-- Users can only read published posts
CREATE POLICY "public_read" ON posts
FOR SELECT USING (published = true);
-- Authors can manage their own posts
CREATE POLICY "author_manage" ON posts
FOR ALL USING (author = current_user);5. Use GraphQL Instead
The same tables are also available via GraphQL:
POST /api/graphql
{
posts(limit: 5, where: { published: true }) {
id
title
author
created_at
}
}