CLI Reference
All yRest functionality is accessible through the yrest CLI. Run yrest --help or yrest <command> --help for inline documentation.
yrest <command> [options]yrest serve
Section titled “yrest serve”Start the mock server from a YAML file.
yrest serve db.yml [options]yrest serve db.yml --port 4000 --watch --delay 200| Flag | Short | Type | Default | Description |
|---|---|---|---|---|
--port | -p | number | 3070 | Port to listen on |
--host | -h | string | localhost | Host to bind |
--base | -b | string | — | URL prefix for all routes (e.g. /api/v1) |
--watch | -w | boolean | false | Reload database on file changes |
--readonly | -r | boolean | false | Reject all write operations (POST/PUT/PATCH/DELETE) |
--delay | -d | number | 0 | Add simulated latency in ms to every response |
--snapshot | -s | boolean | false | Enable /_snapshot save/reset endpoints |
--pageable | — | number? | — | Wrap list responses in { data, pagination } |
--id-strategy | — | increment|uuid | increment | Strategy for auto-assigning id on POST |
Exit codes
Section titled “Exit codes”yrest init
Section titled “yrest init”Scaffold a new db.yml and optional yrest.config.yml in the current directory.
yrest inityrest init --sample relationalyrest init --sample ecommerce| Flag | Type | Description |
|---|---|---|
--sample | basic|relational|ecommerce | Template to use (default: basic) |
--config | boolean | Also create yrest.config.yml |
yrest handler
Section titled “yrest handler”Scaffold a handler function stub in yrest.handlers.js.
yrest handler loginyrest handler login --method POST --path /loginyrest handler login --method POST --path /login --register| Flag | Type | Description |
|---|---|---|
--method | string | HTTP method hint (adds JSDoc comment) |
--path | string | Path hint (adds JSDoc comment) |
--register | boolean | Also add the _routes entry to db.yml |
yrest types
Section titled “yrest types”Generate TypeScript interfaces from the YAML database schema.
yrest types db.ymlyrest types db.yml --output db.types.tsyrest types db.yml --output db.types.ts --watchNext steps
Section titled “Next steps”- Configuration — set serve options permanently in
yrest.config.yml - Quick Start — step-by-step guide for the
servecommand - Handler Functions —
yrest handlercommand in depth