CLI Reference
Questi contenuti non sono ancora disponibili nella tua lingua.
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 |
--handlers | — | string | — | JS or TS file exporting handler functions |
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 |
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.
yrest types
Section titled “yrest types”Generate TypeScript interfaces from a YAML database: one interface per collection, a CollectionName union and a Collections map.
yrest types db.yml # prints to stdoutyrest types db.yml --output db.types.ts # writes a fileyrest types db.yml --output db.types.ts --watch # regenerates on every change| Flag | Short | Type | Default | Description |
|---|---|---|---|---|
--output | -o | string | (stdout) | Write to a file instead of printing to stdout |
--watch | -w | boolean | false | Regenerate on every change of the source file (needs --output) |
Output
Section titled “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[];}Type rules
Section titled “Type rules”- 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;
nulladds| null. Nested objects are merged into one shape and array elements are pooled. _schemawins —_type,_required(and therequired/optionalshorthand),_enum,_nullableand_itemsoverride the inference._description,_formatand_deprecatedbecome JSDoc. Fields declared only in_schemaare included.- Relations —
many2one/one2oneforeign keys from_relget aFK → target.idcomment.
Next 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 - TypeScript Codegen —
yrest typesin depth - Programmatic API — use the generated types with
createYrestServer