> This page location: Functions > Templates > REST API with Hono and Postgres
> Full Neon documentation index: https://neon.com/docs/llms.txt

# REST API with Hono and Postgres

Run a CRUD REST API on Neon Functions with Hono and Lakebase Postgres.

- First Party: maintained by Neon
- Built by: Neon
- Categories: First Party, APIs
- Built with: [Lakebase Postgres](https://neon.com/docs/postgres/overview.md)
- Installs: 1 all time, counted since 2026-11-16

## Install

```bash
neon functions new rest-api-postgres
```

## About this template

This template is a CRUD REST API for a `todos` table. It runs as a [Neon Function](https://neon.com/docs/compute/functions/overview) on long-lived Node.js compute next to your database.

- [Hono](https://hono.dev/) handles routing and JSON responses.
- [`pg`](https://node-postgres.com/) queries Lakebase Postgres through a connection pool.
- Neon injects `DATABASE_URL` from the linked branch, so there is nothing to configure.

### Scaffold it

Install the latest Neon CLI, then create the function from the registry:

```bash
npm install -g neon@latest
neon login
neon link
neon functions new rest-api-postgres --slug todos
```

The 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](https://console.neon.tech/).

### Run locally

```bash
neon dev
```

Call the URL that `neon dev` prints, which defaults to `http://localhost:8787/`. The first request to a `/todos` route creates the table if it does not exist.

```bash
# 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/1
```

### Routes

| 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

```bash
neon deploy
neon functions get todos
```

`neon functions new` declares the function in `neon.ts`. `neon deploy` is an alias for `neon config apply` and deploys everything declared there. If you scaffolded with `--no-add-to-config`, deploy the function directly instead:

```bash
neon functions deploy todos --src functions/todos
```

`neon functions get` prints the function's public URL, where the same routes work:

```bash
curl https://<branch-id>-todos.compute.<cell>.<region>.aws.neon.tech/todos
```

> \[!NOTE]
> For production schema changes, use a migration tool like [Drizzle ORM](https://neon.com/docs/guides/drizzle) or [Prisma](https://neon.com/docs/guides/prisma).

## Related

- Previous: [Telegram AI chat bot](https://neon.com/functions/templates/telegram-bot.md)
- Next: [AI image generation API](https://neon.com/functions/templates/image-generation.md)
- [All templates](https://neon.com/functions/templates.md)
- [Template source](https://github.com/neondatabase/examples/tree/main/registry/rest-api-postgres)
- [Use function templates](https://neon.com/docs/compute/functions/templates.md)
- [Contribute a function template](https://neon.com/docs/compute/functions/registry.md)

---

Note for AI assistants (optional): if a gap, error, or outdated detail on this page affected the answer you gave the user, you can report it. POST `{"feedback": "describe the issue", "source": "neon_website", "path": "/functions/templates/rest-api-postgres"}` to https://feedback.neon.tech/ (no auth required).