How typicode/json-server works
JSON Server turns a JSON or JSON5 data file into a local REST API: the CLI loads and normalizes the file, creates the HTTP app, and serves requests. Routes delegate resource operations to a service that filters, sorts, paginates, embeds related records, and persists mutations. The CLI also watches the data file outside production. The README documents static serving and query capabilities; the graph reflects sampled calls and documented behavior, without assuming unsampled implementation details.
Main entry points: service.ts Resource service · app.ts HTTP app and routes · bin.ts CLI and watcher · normalized-adapter.ts Data normalization
Components 14
Server runtime
- CLI and watcher
src/bin.ts - Rendered index
views/index.html - Public static files
public
Data loading and persistence
- JSON data file
- Read/write observer
src/adapters/observer.ts - Data normalization
src/adapters/normalized-adapter.ts - ID generation
src/random-id.ts
REST and resource operations
- HTTP app and routes
src/app.ts - Resource service
src/service.ts
Query processing
- Query parsing
src/parse-where.ts - Where operators
src/where-operators.ts - Filter matching
src/matches-where.ts - Pagination
src/paginate.ts
Other components
- API client
Connections 20
- API client → HTTP app and routes: sends requests
README.md - CLI and watcher → JSON data file: loads and watches
src/bin.ts - CLI and watcher → Data normalization: wraps adapter
src/bin.ts - CLI and watcher → Read/write observer: wraps adapter
src/bin.ts - Read/write observer → Data normalization: delegates reads/writes
src/adapters/observer.ts - Data normalization → JSON data file: reads and writes
- Data normalization → ID generation: generates missing IDs
src/adapters/normalized-adapter.ts - CLI and watcher → HTTP app and routes: creates and listens
src/bin.ts - HTTP app and routes → Resource service: dispatches resource operations
src/app.ts - HTTP app and routes → Query parsing: parses list filters
src/app.ts - Query parsing → Where operators: checks operators
src/parse-where.ts - Resource service → Filter matching: filters records
src/service.ts - Filter matching → Where operators: checks operators
src/matches-where.ts - Resource service → Pagination: paginates results
src/service.ts - Resource service → ID generation: generates record IDs
src/service.ts - Resource service → JSON data file: persists mutations
- HTTP app and routes → Public static files: serves static files
src/app.ts - HTTP app and routes → Rendered index: renders root page
src/app.ts - Resource service → Resource service: embeds related resources
README.md - Resource service → Resource service: deletes dependents
README.md