Skip to content

Configuration

Alejandro Lugo edited this page Jun 7, 2026 · 2 revisions

yrest resolves options from three sources in ascending priority:

schema defaults → yrest.config.yml → CLI flags

Only flags explicitly passed on the command line override the config file. Defaults never shadow values set in the config file.


Config file

Run yrest init to generate a yrest.config.yml template, or create it manually:

file: db.yml        # YAML database file
port: 3070          # Port to listen on
host: localhost     # Host to bind
# base: /api        # Base path prefix for all routes
# watch: false      # Reload db file on change
# readonly: false   # Block write operations (POST, PUT, PATCH, DELETE)
# delay: 0          # Simulated network latency in milliseconds
# pageable: false   # Wrap GET collections in { data, pagination }
# snapshot: false   # Save initial db state and expose /_snapshot endpoints

yrest looks for yrest.config.yml in the current working directory. If it does not exist, all values fall back to their defaults.


CLI flags

yrest serve [file] [options]
Flag Short Default Description
--port <number> -p 3070 Port to listen on
--host <host> -H localhost Host to bind
--base <path> -b `` Base path prefix (e.g. /api)
--watch -w false Reload db file on change
--readonly -r false Block all write operations
--delay <ms> -d 0 Simulated latency in ms
--pageable [limit] false Pageable envelope (default limit: 10)
--snapshot false Enable snapshot endpoints

All options reference

file

Path to the YAML database file. Relative to the current working directory.

yrest serve db.yml
yrest serve data/mock.yml

Default: db.yml


port

Port the HTTP server listens on.

yrest serve --port 8080

Default: 3070


host

Host the server binds to. Use 0.0.0.0 to expose on all network interfaces.

yrest serve --host 0.0.0.0

Default: localhost


base

URL prefix applied to all resource routes. Does not affect meta endpoints (/_about, /_snapshot).

yrest serve --base /api
# Routes become: /api/users, /api/posts, etc.

Default: (empty — routes start at /)


watch

Reloads the YAML file automatically when it changes on disk. Useful during development when you edit the database manually.

yrest serve --watch

Adding or removing entire collections requires a server restart. Only changes within existing collections are picked up on reload.

Default: false


readonly

Rejects all mutating requests (POST, PUT, PATCH, DELETE) with 405 Method Not Allowed. GET requests are unaffected.

yrest serve --readonly

Default: false


delay

Adds a fixed delay (in milliseconds) to every response. Useful for simulating real network latency in frontend development.

yrest serve --delay 300

Default: 0


pageable

Wraps GET collection responses in a { data, pagination } envelope. Accepts true (default limit: 10) or a number to set the default page size.

yrest serve --pageable          # limit: 10
yrest serve --pageable 25       # limit: 25

Config file:

pageable: true    # limit: 10
pageable: 25      # limit: 25

Default: false


snapshot

Saves a deep copy of the database state at startup and exposes three endpoints:

  • GET /_snapshot — snapshot metadata and item counts
  • POST /_snapshot/save — update the snapshot to the current state
  • POST /_snapshot/reset — restore the database to the last snapshot
yrest serve --snapshot

Default: false


Init command

yrest init [options]
Flag Short Default Description
--file <name> -f db.yml Output filename for the database
--sample <name> -s basic Sample template to use

Available samples: basic, relational

yrest init                        # basic sample → db.yml
yrest init --sample relational    # relational sample with _rel
yrest init --file mock.yml        # custom filename

Clone this wiki locally