Transform your database schema into a REST API in seconds.
A dynamic REST API adapter for Drizzle ORM with JSON-Server compatible query syntax
Transform your Drizzle schema into a fully functional REST API with a single function call. Perfect for rapid prototyping, admin panels, and seamless migration from JSON-Server.
- 🚀 Zero Configuration: Generate REST endpoints from your Drizzle schema instantly
- 🔍 JSON-Server Compatible: Familiar query syntax for filtering, sorting, and pagination
- 🎣 Hook System: Authorization, data transformation, and custom logic with
beforeOperationandafterOperationhooks - 🗄️ PostgreSQL Support: Full PostgreSQL database support
npm install drizzle-rest-adapterimport express from 'express';
import { createDrizzleRestAdapter } from 'drizzle-rest-adapter';
import { db } from './db/connection'; // Your Drizzle instance
import * as schema from './db/schema'; // Your Drizzle schema
const app = express();
app.use(express.json());
// Create the REST API adapter
const apiRouter = createDrizzleRestAdapter({
db: db,
schema: schema,
});
// Mount the generated API
app.use('/api/v1', apiRouter);
app.listen(3000, () => {
console.log('REST API running on http://localhost:3000/api/v1');
});That's it! Your API is now available with full CRUD operations for all tables in your schema.
# Get all users
GET /api/v1/users
# Get user by ID
GET /api/v1/users/123
# Create new user
POST /api/v1/users
Content-Type: application/json
{ "name": "John Doe", "email": "john@example.com" }
# Update user (partial)
PATCH /api/v1/users/123
Content-Type: application/json
{ "name": "Jane Doe" }
# Replace user (complete)
PUT /api/v1/users/123
Content-Type: application/json
{ "name": "Jane Doe", "email": "jane@example.com" }
# Delete user
DELETE /api/v1/users/123# Direct equality
GET /api/v1/users?status=active
# Range filters
GET /api/v1/users?age_gte=18&age_lte=65
# String search (substring)
GET /api/v1/users?name_like=John
# Negation
GET /api/v1/users?status_ne=inactive
# Array membership (multiple IDs)
GET /api/v1/users?id=1&id=2&id=3# Page-based pagination
GET /api/v1/users?_page=2&_per_page=25
# Range-based pagination
GET /api/v1/users?_start=10&_end=20
GET /api/v1/users?_start=10&_limit=10# Single field ascending
GET /api/v1/users?_sort=name
# Single field descending
GET /api/v1/users?_sort=-created_at# Embed related data
GET /api/v1/posts?_embed=author
GET /api/v1/posts?_embed=author,commentsMigrating from JSON-Server? The query syntax is 100% compatible:
Currently supports PostgreSQL databases:
- ✅ PostgreSQL (PGlite and standard PostgreSQL)
We welcome contributions! This is an alpha project, so expect rapid changes and improvements.
Alpha Contributors Welcome: Since this is an alpha release, your feedback and contributions are especially valuable in shaping the final API.
Please see CONTRIBUTING.md for guidelines.
git clone https://github.com/mgaebler/drizzle-rest.git
cd drizzle-rest
npm install
npm run devnpm test # Run all tests
npm run test:watch # Watch mode
npm run lint # Lint codeMIT License - see LICENSE file for details.
- Drizzle ORM for the excellent database toolkit
- JSON-Server for the API design inspiration
Made with ❤️ for the Drizzle community