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-restfronds/blog/entities/Post.ts
1
import { entity, oneOf, primary, text } from '@fougere/schema';2
3
export default class Post extends entity({c e g4
id: primary(),5
title: text({ min: 1, max: 160 }),d h6
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.