Hono
Build a Hono API on Prisma ORM with the hono template, add your own routes, and deploy it to Prisma Compute.
Introduction
In this guide, you scaffold a Hono API backed by Prisma ORM, initialize and seed a PostgreSQL database, serve data over HTTP, add your own POST route, and deploy the API to Prisma Compute. The hono template generates the server for you, so most of the work is understanding the pieces and extending them.
Every command, route, and response below was run end to end against a live Prisma Postgres database.
Prerequisites
- Node.js 22.18 or newer on the 22 line, 24.11 or newer on the 24 line, or 26 or newer (24 recommended), or Bun (this guide uses Bun for speed; npm works the same)
- A PostgreSQL connection string, or nothing at all: the scaffold can create a Prisma Postgres database for you
1. Scaffold the project
bun create prisma@latest my-hono-api --template hono --provider postgres --no-deployAnswer the prompts for contract authoring style, package manager, and agent skills. The template generates a Hono server in src/index.ts with two routes (GET / and GET /users), the Prisma ORM setup in src/prisma/, and package scripts for the database steps.
cd my-hono-apiNext, set the database connection for the local steps. Use your own PostgreSQL connection string, or create a Prisma Postgres database with npx create-db@latest; it prints a connection string and a claim URL; claim it with a free Prisma account to keep the database. Export the variable in the shell you work in; the generated scripts read the environment variable, not .env:
export DATABASE_URL="<your connection string>"2. Initialize the database
bun run db:init"summary": "Applied 5 operation(s) across 1 space(s), database signed"If db:init stops with Connection terminated unexpectedly, a database you just created is still starting; wait a few seconds and run it again. The command is safe to repeat and reports Applied 0 operation(s) when there is nothing left to do.
3. Run the server
bun run devThe server starts on port 3000 (set PORT to change it). Check both routes:
curl http://localhost:3000/users[
{ "id": "1", "email": "alice@prisma.io", "username": "alice", "name": "Alice", "createdAt": "2026-07-06T23:37:32.440Z" },
{ "id": "2", "email": "bob@prisma.io", "username": "bob", "name": "Bob", "createdAt": "2026-07-06T23:37:32.474Z" },
{ "id": "3", "email": "carol@prisma.io", "username": "carol", "name": "Carol", "createdAt": "2026-07-06T23:37:32.507Z" }
]The route handler is ordinary Hono code calling an ordinary Prisma ORM query; there is no framework adapter in between.
4. Add a POST route
Add a route that creates a user from the request body. Add this to src/index.ts above the serve(...) call:
app.post("/users", async (c) => {
const body = await c.req.json<{ email: string; name?: string }>();
const { db } = await import("./prisma/db");
const user = await db.orm.public.User.create({
email: body.email,
name: body.name ?? null,
});
return c.json(user, 201);
});Restart the server and create a user:
curl -X POST http://localhost:3000/users \
-H "content-type: application/json" \
-d '{"email":"dev@prisma.io","name":"Dev"}'{ "createdAt": "2026-07-06T23:37:56.184Z", "email": "dev@prisma.io", "id": 4, "name": "Dev", "username": null }.create(...) returns the full inserted record, database defaults included, so the response needs no second query.
5. Deploy to Prisma Compute
Hono is supported on Prisma Compute. The scaffold already declares the app for Prisma Composer in module.ts and service.ts, so deploying is building and handing that declaration to the CLI. Sign in once (it opens a browser):
npx prisma auth loginThen build and deploy from the project directory:
npm run build
npx prisma deploymy-hono-api
├─ database postgres-database db_abc123
└─ app compute-service cps_abc123
https://xyz.ewr.prisma.buildThe deploy creates a project named after your module in your workspace, and re-running the deploy reuses it: the CLI finds the hosted state it stored on the first run and converges the project to your module. If a project with that name exists but the CLI cannot identify or verify its stored state (one left behind by a different checkout, for example), the deploy stops with HostedStateBootstrapError; deploy under another name with --name <unique-name>, or rename the module in module.ts. The deploy also provisions its own Prisma Postgres database on the platform, declared in module.ts; the DATABASE_URL from your local steps is not involved. Verify the live endpoint returns the seeded users (the deployed database seeds on its first query):
curl https://xyz.ewr.prisma.build/usersFor previews per Git branch and deploy on push, see Deploy on push.
Common gotchas
In a long-running server, don't call db.close() in route handlers; the client's connection pool is shared across requests. Close it only on process shutdown.
Use with your agent
To delegate this guide to your coding agent, copy the prompt below and hand it over:
The prompt above runs npx prisma@latest init in its first step. If you followed the steps by hand, run it once yourself: it installs the Prisma ORM skills for your coding agent and keeps them matching your installed packages. Prompts you can give your agent after this guide:
- "Using the prisma-8 skill, add GET /users/ that returns one user or a 404."
- "Expose GET /users//posts using the Post model that ships with the starter contract."
- "Wrap the signup route's writes in a transaction."
Next steps
- Learn the fundamentals: filtering, sorting, pagination, and writes.
- Read the Prisma ORM overview for the concepts behind contracts and typed queries.
Updated