This template is a CRUD REST API for a todos table. It runs as a Neon Function on long-lived Node.js compute next to your database.
- Hono handles routing and JSON responses.
pgqueries Lakebase Postgres through a connection pool.- Neon injects
DATABASE_URLfrom the linked branch, so there is nothing to configure.
Scaffold it
Install the latest Neon CLI, then create the function from the registry:
npm install -g neon@latest
neon login
neon link
neon functions new rest-api-postgres --slug todosThe CLI writes functions/todos/index.ts, declares todos in neon.ts, and installs the template's dependencies.
neon link pulls DATABASE_URL into .env.local. You can also find the connection string in the Neon Console.
Run locally
neon devCall the URL that neon dev prints (the default is http://localhost:8787/). The first request to a /todos route creates the table if it does not exist.
# Describe the API
curl http://localhost:8787/
# Create a todo
curl -X POST http://localhost:8787/todos \
-H 'content-type: application/json' \
-d '{"title":"ship it"}'
# List todos
curl http://localhost:8787/todos
# Complete a todo
curl -X PATCH http://localhost:8787/todos/1 \
-H 'content-type: application/json' \
-d '{"completed":true}'
# Delete a todo
curl -X DELETE http://localhost:8787/todos/1Routes
| Method | Path | Body | Result |
|---|---|---|---|
GET | / | None | The API name and route list |
GET | /todos | None | Up to 100 todos, newest first |
POST | /todos | { "title": string, "completed"?: boolean } | 201 with the created todo |
GET | /todos/:id | None | The todo, or 404 |
PATCH | /todos/:id | { "title"?: string, "completed"?: boolean } | The updated todo, or 404 |
DELETE | /todos/:id | None | 204, or 404 |
A non-numeric :id, a body that isn't a JSON object, an empty title, or a non-boolean completed returns 400. Any other path or method returns 404.
Deploy
neon deploy
neon functions get todosneon functions new declares the function in neon.ts, and neon deploy (an alias for neon config apply) deploys everything declared there. If you scaffolded with --no-add-to-config, deploy the function directly instead:
neon functions deploy todos --src functions/todosneon functions get prints the function's public URL, where the same routes work:
curl https://<branch-id>-todos.compute.<cell>.<region>.aws.neon.tech/todos[!NOTE] For production schema changes, use a migration tool like Drizzle ORM or Prisma.








