Skip to content

CLI Reference

All yRest functionality is accessible through the yrest CLI. Run yrest --help or yrest <command> --help for inline documentation.

Terminal window
yrest <command> [options]

Start the mock server from a YAML file.

Terminal window
yrest serve db.yml [options]
yrest serve db.yml --port 4000 --watch --delay 200
FlagShortTypeDefaultDescription
--port-pnumber3070Port to listen on
--host-hstringlocalhostHost to bind
--base-bstring—URL prefix for all routes (e.g. /api/v1)
--watch-wbooleanfalseReload database on file changes
--readonly-rbooleanfalseReject all write operations (POST/PUT/PATCH/DELETE)
--delay-dnumber0Add simulated latency in ms to every response
--snapshot-sbooleanfalseEnable /_snapshot save/reset endpoints
--pageable—number?—Wrap list responses in { data, pagination }
--id-strategy—increment|uuidincrementStrategy for auto-assigning id on POST
--handlers—string—JS or TS file exporting handler functions

Scaffold a new db.yml and optional yrest.config.yml in the current directory.

Terminal window
yrest init
yrest init --sample relational
yrest init --sample ecommerce
FlagTypeDescription
--samplebasic|relational|ecommerceTemplate to use (default: basic)
--configbooleanAlso create yrest.config.yml

Scaffold a handler function stub in yrest.handlers.js.

Terminal window
yrest handler login
yrest handler login --method POST --path /login
yrest handler login --method POST --path /login --register
FlagTypeDescription
--methodstringHTTP method hint (adds JSDoc comment)
--pathstringPath hint (adds JSDoc comment)
--registerbooleanAlso add the _routes entry to db.yml

The stub goes to the file set by handlers: in yrest.config.yml, or yrest.handlers.js. For a .ts / .mts file it uses defineHandler. --register writes the entry with _method, _path and _handler. See Handler Functions.

Generate TypeScript interfaces from a YAML database: one interface per collection, a CollectionName union and a Collections map.

Terminal window
yrest types db.yml # prints to stdout
yrest types db.yml --output db.types.ts # writes a file
yrest types db.yml --output db.types.ts --watch # regenerates on every change
FlagShortTypeDefaultDescription
--output-ostring(stdout)Write to a file instead of printing to stdout
--watch-wbooleanfalseRegenerate on every change of the source file (needs --output)
// Auto-generated by yrest types — do not edit manually.
// Source: db.yml
/** Item of the `users` collection. */
export interface User {
id: number;
name: string;
email?: string;
}
/** Item of the `posts` collection. */
export interface Post {
id: number;
title: string;
/** FK → users.id */
userId: number;
}
/** Union of all collection names in the source file. */
export type CollectionName = "users" | "posts";
/** Maps each collection name to its item array type. */
export interface Collections {
users: User[];
posts: Post[];
}
  • Names — collection name in singular PascalCase: users → User, post_tags → PostTag, categories → Category. On a collision the plural form is kept.
  • Optionality — inferred from every item: present on all items → required, missing on any → optional.
  • Unions — different types across items become a union; null adds | null. Nested objects are merged into one shape and array elements are pooled.
  • _schema wins — _type, _required (and the required / optional shorthand), _enum, _nullable and _items override the inference. _description, _format and _deprecated become JSDoc. Fields declared only in _schema are included.
  • Relations — many2one / one2one foreign keys from _rel get a FK → target.id comment.