@zapi-x/core
v0.1.0-beta.3
Published
Zero to API in seconds - Entity-first, type-safe API framework
Maintainers
Readme
Zapi
Zero to API in seconds - Entity-first, type-safe API framework
⚠️ Beta Software: APIs may change before v1.0. Use in production at your own risk.
Features
- 🚀 Entity-first - Define your entities, get your API
- 🔒 Type-safe - Full TypeScript support with inference
- 🔌 Framework agnostic - Express, Hono, and more
- 🗄️ Database agnostic - Prisma, and more coming
- 🧩 Plugin system - Auth, timestamps, and custom plugins
- ⚡ Zero config - Sensible defaults, override when needed
Installation
npm install @zapi-x/core
# or
pnpm add @zapi-x/coreQuick Start
import { entity, string, text, belongsTo } from "@zapi-x/core"
import { zapi } from "@zapi-x/core"
// 1. Define entities
const user = entity("user", {
email: string.unique(),
name: string.min(1).max(100),
})
.build()
const post = entity("post", {
title: string,
content: text,
author: belongsTo(() => user),
})
.ownedBy("author")
.build()
// 2. Mount to your framework (Express + Prisma example)
import express from "express"
import { expressAdapter, expressDevAuth } from "@zapi-x/core/adapters/express"
import { prisma } from "@zapi-x/core/drivers/prisma"
import { PrismaClient } from "@prisma/client"
const app = express()
const prisma = new PrismaClient()
const api = zapi({
entities: [user, post],
driver: prisma(prisma),
})
app.use("/api", expressAdapter(api, { getUser: expressDevAuth, cors: true }))
app.listen(3000)Entity DSL
import { entity, string, text, int, bool, datetime, belongsTo, hasMany } from "@zapi-x/core"
const task = entity("task", {
// String fields
title: string.min(1).max(200),
description: text.optional(),
// Other types
priority: int.default(0).min(0).max(3),
completed: bool.default(false),
dueDate: datetime.optional(),
// Relations
project: belongsTo(() => project),
assignee: belongsTo(() => user),
})
.ownedBy("assignee") // Auto-set owner on create
.rules({
create: ["authenticated"],
read: ["everyone"],
update: ["owner", "admin"],
delete: ["admin"],
})
.build()Adapters
Import only what you need:
// Express
import { expressAdapter, expressDevAuth, expressJwtAuth } from "zapi/adapters/express"
// Hono
import { honoAdapter, honoDevAuth, honoJwtAuth, cookieAuth } from "zapi/adapters/hono"Drivers
// Prisma
import { prisma } from "zapi/drivers/prisma"Plugins
// Timestamps (adds createdAt/updatedAt globally)
import { timestamps } from "zapi/plugins/timestamps"
// Auth helpers are provided via adapters (dev/jwt) to keep Zapi auth-agnostic
// import { expressDevAuth, expressJwtAuth } from "zapi/adapters/express"Generated Files
Use the generator to create Prisma schema, TypeScript types, and API client:
import { generate } from "@zapi-x/generator"
import { entities } from "./entities"
generate(entities, {
outDir: "./generated",
prismaProvider: "sqlite",
})This generates:
generated/prisma/schema.prisma- Prisma schemagenerated/types.ts- TypeScript interfacesgenerated/client.ts- Type-safe API client
API Endpoints
For each entity, zapi generates:
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | /users | List with filter/sort/pagination |
| POST | /users | Create |
| GET | /users/:id | Get by ID |
| PUT | /users/:id | Update |
| DELETE | /users/:id | Delete |
Query Parameters
# Filtering
GET /users?filter[role]=admin
# Sorting
GET /posts?sort=-createdAt
# Pagination
GET /posts?limit=10&offset=20
# Include relations
GET /posts?include=authorLicense
MIT © 2025
