HOPAK.JS · v0.5

A backend framework for Bun.

File-based routing. Typed models. Scaffolded CRUD.

$ bun add -g @hopak/cli
Quick start

How it works

Model

Fields, constraints, relations.

app/models/post.ts
import { model, text, boolean, belongsTo } from '@hopak/core';

export default model('post', {
  title: text().required().min(3).max(200),
  content: text().required(),
  published: boolean().default(false),
  author: belongsTo('user'),
});

The declaration creates the table columns, the TypeScript row type, and the validator.

Routes

Two files. Six endpoints.

$ hopak generate crud post
Created app/routes/api/posts.ts
Created app/routes/api/posts/[id].ts
app/routes/api/posts.ts
import { crud } from '@hopak/core';
import post from '../../models/post';

export const GET = crud.list(post);
export const POST = crud.create(post);

The generated files are regular TypeScript. Edit an endpoint or remove it at any time.

Response

A request against the running server.

$ curl localhost:3000/api/posts
HTTP/1.1 200 OK
{
  "items": [
    { "id": 1, "title": "Hello", "published": true, "author_id": 4 }
  ],
  "total": 1,
  "limit": 20,
  "offset": 0
}

The server validates input, hides sensitive fields, and paginates list endpoints.