Configs2026年5月29日·1 分钟阅读

JSON Server — Full Fake REST API with Zero Coding

A Node.js tool that turns a JSON file into a fully functional REST API in seconds. Useful for frontend prototyping, mocking backends during development, and creating demo APIs without writing any server code.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
JSON Server Overview
直接安装命令
npx -y tokrepo@latest install b92132b4-5b7a-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

JSON Server provides a full fake REST API from a single JSON file. It was created to let frontend developers prototype and develop against a realistic API without waiting for backend teams. Point it at a db.json file and you get GET, POST, PUT, PATCH, and DELETE routes with pagination, filtering, sorting, and full-text search.

What JSON Server Does

  • Creates RESTful CRUD endpoints from any JSON file automatically
  • Supports filtering, pagination, sorting, and full-text search via query parameters
  • Watches the JSON file for changes and reflects them in real time
  • Serves static files from a public directory alongside the API
  • Supports custom routes, middleware, and programmatic usage as a Node.js module

Architecture Overview

JSON Server is built on Express.js. It reads a JSON file as an in-memory lowdb database, generates RESTful routes for each top-level key, and writes changes back to the file. Custom middleware can be added to intercept requests, and a routes.json file enables URL rewriting to simulate complex API structures.

Self-Hosting & Configuration

  • Install globally with npm or use npx for one-off usage without installation
  • The --port flag changes the default port from 3000
  • Add a routes.json file for custom URL mappings like /api/v1/posts to /posts
  • Use --middlewares to inject custom Express middleware for auth simulation or logging
  • Mount JSON Server as middleware inside an existing Express app for hybrid setups

Key Features

  • Instant REST API from a flat JSON file with zero boilerplate
  • Full CRUD operations with automatic ID generation for new records
  • Query parameter support for _page, _limit, _sort, _order, and q (search)
  • Relationships via _expand and _embed for nested resource responses
  • Snapshot feature saves the current database state on demand

Comparison with Similar Tools

  • MSW (Mock Service Worker) — intercepts requests at the network level in the browser; JSON Server runs as a real HTTP server
  • Mirage.js — in-memory mock server that runs in the browser; JSON Server provides a standalone process accessible from any client
  • WireMock — Java-based HTTP mock with request matching; heavier setup than JSON Server's single-file approach
  • Mockoon — desktop GUI for designing mock APIs; JSON Server is CLI-first and scriptable

FAQ

Q: Does JSON Server persist data? A: Yes, changes are written back to the JSON file on disk. Restarting the server reloads from the file.

Q: Can I use it in production? A: JSON Server is designed for development and prototyping. It uses a flat file as storage and lacks authentication, rate limiting, and other production requirements.

Q: How do I add authentication? A: Add custom Express middleware via the --middlewares flag or mount JSON Server inside a larger Express app that handles auth.

Q: Does it support nested resources? A: Use _embed to include child resources and _expand to include parent resources in responses.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产