lacspace-mock

Local mock REST/GraphQL from JSON or OpenAPI.

● Live · v0.2.0npm ↗Source ↗
terminal
npx lacspace-mock --db db.json
What it does

Everything, in one command

Frontend teams shouldn't have to wait for a backend to exist. lacspace-mock reads a db.json and instantly serves REST CRUD for every collection, answers custom routes described in a small JSON config (templated with path params, request-body fields and a seeded faker), and resolves a pragmatic GraphQL subset — all on node:http with no runtime dependencies. Because the same engine is an importable, port-free library, it doubles as a test fixture: construct a request, assert the response, no sockets. Latency and error-rate knobs let you rehearse loading states and failure handling before you ever hit a real server.

Features

What's inside

Auto REST CRUD

Every JSON collection becomes GET/POST/PUT/PATCH/DELETE with proper status codes and headers.

Rich list queries

Pagination, multi-key sort, field filters, _gte/_lte/_ne/_like operators and full-text q.

Templated custom routes

{{params}}, {{query}}, {{body}}, {{repeat n}} and a seeded faker ({{fake.email}}, {{fake.uuid}}…).

Network simulation

Global/per-route delay (fixed or jitter) and an --error-rate chaos switch for random 500s.

Minimal GraphQL

One POST /graphql resolves collection queries with id/limit args and nested field selection.

Library + CLI

A pure, port-free createEngine().handle() makes it unit-testable and embeddable.

Private by default

Binds to 127.0.0.1, CORS on, --write to persist, zero deps, no telemetry.

Mock from OpenAPI 3

Generate routes + example responses from any spec's component schemas.

Request validation

Reject malformed bodies/params with a 400 + details (per-route or per-collection).

Chaos status pools

Fail a % of responses with any statuses you choose (429,503,…), not just 500.

Record & replay proxy

Forward unknown routes to a real upstream, capture responses, replay them offline.

Stateful CRUD + reset

Mutations persist for the session; reset() snaps the db back for clean test runs.

How to use

Copy, paste, done

Real commands and snippets — from a one-liner to the typed library.

Serve a JSON db
terminal
npx lacspace-mock --db db.json

CRUD for every collection at http://127.0.0.1:4000.

Filter, sort, paginate
terminal
curl 'localhost:4000/users?role=admin&_sort=age&_order=desc&_limit=10'

operators, q, and X-Total-Count header included.

Custom + fake data
terminal
npx lacspace-mock --config mock.config.json

templated routes with {{params}}, {{body}}, {{fake.*}}, {{repeat}}.

Rehearse a slow, flaky API
terminal
npx lacspace-mock --db db.json --delay 50-400 --error-rate 0.1

jittered latency + 10% random 500s.

GraphQL over the db
terminal
curl -X POST localhost:4000/graphql -d '{"query":"{ users(id:1){ id name } }"}'

pragmatic subset: id/limit args, nested selection.

Mock an OpenAPI spec
terminal
npx lacspace-mock --openapi openapi.json

One route per operation, example bodies from your schemas.

Chaos with a status pool
terminal
npx lacspace-mock db.json --error-rate 0.2 --error-statuses 429,503

20% of responses fail with a 429 or 503.

Record then replay offline
terminal
npx lacspace-mock --db db.json --proxy https://api.example.com --record --recordings tape.json

Re-run with --replay to serve the cassette with no network.

Good for

What people build with it

✓ Prototype a UI before the backend exists

✓ Deterministic API fixtures for integration tests

✓ Rehearse loading/error states with latency + chaos

✓ Local contract stubs for a third-party API

Start now

Run lacspace-mock today

Free, open-source, no API keys. It's a CLI and a typed library.

terminal
npx lacspace-mock --db db.json