Quick Start
Getting a full mock REST API running with yRest takes under a minute. All you need is a YAML file — no server code, no configuration, no database to set up. The four steps below take you from zero to a live API you can call from your frontend.

1. Create your database file
Section titled “1. Create your database file”The init command scaffolds a ready-to-use db.yml and a yrest.config.yml in the current directory:
npx @yrest/cli initThree built-in templates are available via --sample:
| Template | What it contains |
|---|---|
basic(default) |
|
relational |
|
ecommerce |
|
npx @yrest/cli init --sample relational # relational templatenpx @yrest/cli init --sample ecommerce # e-commerce templatenpx @yrest/cli init --file api.yml # custom output filenameYou can also skip init entirely and write the file by hand — the format is just YAML:
users: - id: 1 name: Ana email: ana@test.com - id: 2 name: Luis email: luis@test.com
posts: - id: 1 title: First post userId: 1Any top-level key that doesn’t start with _ becomes a collection with full CRUD routes.
2. Start the server
Section titled “2. Start the server”With your db.yml ready, start the server with a single command. yRest reads the file, registers a full CRUD route for every collection, and begins listening — no compilation step, no database setup, no config file required.
npx @yrest/cli serve db.ymlyrest · http://localhost:3070
Collections (base: /): CRUD /users CRUD /posts
Meta: GET /_aboutThe default port is 3070. It was chosen to avoid conflicts with the most common development ports (3000, 3001, 4000, 8080, 8000) while staying in a familiar range, so you can run yRest alongside your real frontend dev server without touching any config.
Available flags:
| Flag | Default | Description |
|---|---|---|
-p, —port <n> | 3070 | Port to listen on |
-H, —host <host> | localhost | Host to bind (use |
-b, —base <path> | (none) | Prefix all routes — e.g. |
-w, —watch | off | Reload |
-r, —readonly | off | Reject all writes (POST/PUT/PATCH/DELETE → 405) |
-d, —delay <ms> | 0 | Add a fixed latency to every response |
—pageable [limit] | off | Wrap list responses in |
—snapshot | off | Expose |
—handlers <file> | (none) | Path to a |
—id-strategy <s> | increment |
|
Options can also be set in yrest.config.yml so you don’t need to repeat them on every run. CLI flags always take priority over the config file.
3. Use the API
Section titled “3. Use the API”Every collection gets the full REST surface automatically. Here are the most common operations against the users collection from the example above:
# List all userscurl http://localhost:3070/users
# Get a single user by idcurl http://localhost:3070/users/1
# Filter by field valuecurl "http://localhost:3070/users?name_like=ana"
# Paginatecurl "http://localhost:3070/users?_page=1&_limit=10"
# Sortcurl "http://localhost:3070/users?_sort=name&_order=asc"
# Create a new user (id is assigned automatically)curl -X POST http://localhost:3070/users \ -H "Content-Type: application/json" \ -d '{"name":"Carlos","email":"carlos@test.com"}'
# Partial updatecurl -X PATCH http://localhost:3070/users/1 \ -H "Content-Type: application/json" \ -d '{"name":"Ana Updated"}'
# Deletecurl -X DELETE http://localhost:3070/users/1Changes made via POST/PUT/PATCH/DELETE are persisted back to db.yml in real time. Restart the server to reset to the original data, or enable --snapshot and call POST /_snapshot to save the current state explicitly.
4. Explore the API overview
Section titled “4. Explore the API overview”Open http://localhost:3070/_about in your browser.
This built-in page shows every generated endpoint grouped by collection, the active server modes, any custom routes defined in _routes, and ready-to-run curl examples for each operation. It updates automatically when the server reloads — useful as a quick reference while you build your frontend.
Next steps
Section titled “Next steps”- Configuration — all
yrest.config.ymloptions - Database format — learn the full YAML schema
- Query parameters — filters, sorting, pagination, projections
- Relations — link collections with
_rel - Custom routes — add non-CRUD endpoints
- Programmatic API — use in Vitest and Playwright