1. Start
  2. An entity
  3. A source
  4. A rule
  5. A port
  6. A link
  7. A fact
  8. An app
  9. Split

One entity, and a whole CRUD

We write a Post entity and the handler that serves its rows, then start the app with npx fougere dev blog. It answers on port 4100 and keeps the rows in memory.

Install
$ npm install @fougere/adapter-rest
fronds/blog/entities/Post.ts
1import { entity, oneOf, primary, text } from '@fougere/schema';
2
3export default class Post extends entity({c e g
4 id: primary(),
5 title: text({ min: 1, max: 160 }),d h
6 status: oneOf('draft', 'published', { default: 'draft' }),
7}) {}

point at a lettered line, or tap it, to see what grows from it

Two classes and one line of config. Everything around them is read from these.

Try it
$ curl -X POST localhost:4100/api/blog/posts -d '{"title":""}'
422  VALIDATION_FAILED  title: String is too short (0 < 1).

PATCH /api/blog/posts/:id with { status: 'published' } passes here: nothing guards it yet. A rule, two steps on, closes it.

Built with Fougere and Nuxt, hosted on GitHub Pages.