How to Build a Fake REST API in Minutes (with JSONPlaceholder)

Use json-server to turn a JSON file into a full REST API in seconds, call JSONPlaceholder with zero setup, and learn when to move up to a schema-aware mock.

INEZA Felin-Michel

INEZA Felin-Michel

17 June 2026

How to Build a Fake REST API in Minutes (with JSONPlaceholder)

Apidog for Enterprise

On-Premises Deploy

SSO & RBAC

SOC 2 Compliant

Explore Apidog Enterprise

You’re building a frontend, but the backend isn’t ready. You need a REST API that returns realistic JSON right now, with working GET, POST, PUT, and DELETE, so you can keep coding instead of waiting.

That’s what json-server is for. Point it at a single JSON file and it serves a full REST API in seconds, no backend code required. Its sibling, JSONPlaceholder, goes one step further: a hosted fake API you can call without installing anything. This guide shows how to use both, where they run out of road, and when to move up to a schema-aware mock in Apidog.

button

For the bigger picture on faking endpoints, see what a mock API is. Here we focus on the two tools developers reach for first.

What is json-server?

json-server is an open-source npm tool that turns a plain JSON file into a real REST API. You write a db.json file describing your resources, run one command, and you get standard CRUD routes backed by that file. Write requests actually modify the file, so the data persists between requests during your session.

It’s the fastest way to get a working API for prototyping, frontend development, demos, and tests, without standing up a database or writing server code. The project lives on GitHub and is widely used for exactly this job.

Install and run json-server

Install it from npm:

npm install json-server

Create a db.json file in your project. Top-level array keys become collection routes; top-level objects become single-resource routes:

{
  "posts": [
    { "id": "1", "title": "First post", "views": 100 },
    { "id": "2", "title": "Second post", "views": 250 }
  ],
  "comments": [
    { "id": "1", "text": "Nice work", "postId": "1" }
  ],
  "profile": {
    "name": "apidog"
  }
}

Start the server:

npx json-server db.json

It runs at http://localhost:3000 by default. That’s it; you now have a live API.

Note on versions: json-server v1 dropped the old --watch flag, so npx json-server db.json is the current command. If you’re on the older 0.x line you’ll still see json-server --watch db.json in tutorials.

The routes you get for free

From the db.json above, json-server generates a complete REST surface.

For the posts array:

GET    /posts
GET    /posts/:id
POST   /posts
PUT    /posts/:id
PATCH  /posts/:id
DELETE /posts/:id

For the profile object:

GET   /profile
PUT   /profile
PATCH /profile

Querying is built in too. The v1 syntax uses a colon for conditions:

GET /posts?views:gt=100       # views greater than 100
GET /posts?views:lte=50       # views less than or equal to 50
GET /posts?_sort=-views       # sort by views, descending
GET /posts?_page=1&_per_page=25   # pagination
GET /posts?_embed=comments    # include related comments

Available operators include lt, lte, gt, gte, eq, ne, in, contains, startsWith, and endsWith. For a flat file and one command, that’s a lot of API.

JSONPlaceholder: a fake API with zero setup

Sometimes you don’t even want to install a tool. JSONPlaceholder, from the same author, is a free fake REST API hosted at jsonplaceholder.typicode.com. You call it straight from your code:

curl https://jsonplaceholder.typicode.com/posts/1
{
  "userId": 1,
  "id": 1,
  "title": "sunt aut facere repellat provident",
  "body": "quia et suscipit..."
}

It ships with six ready-made resources:

It accepts POST, PUT, PATCH, and DELETE too, but here’s the catch: writes are faked. The API returns a realistic response as if the change happened, but nothing is saved. Refresh and your “new” post is gone. That’s fine for wiring up UI code against predictable data; it’s not a real backend.

json-server vs JSONPlaceholder

json-server JSONPlaceholder
Setup Install npm package, write db.json None, just call the URL
Runs Locally, your machine Hosted, public
Custom data Yes, your own resources No, fixed resources
Writes persist Yes, to db.json No, faked
Best for Prototyping with your own shapes Quick demos and learning

Reach for JSONPlaceholder when you want data this minute and don’t care what it is. Reach for json-server when you need your own resources and writes that stick.

Where these tools run out of road

json-server and JSONPlaceholder are excellent at one thing: serving JSON fast. They start to hurt once a project grows past a solo prototype.

If you’ve outgrown a flat file, our roundups of tools for mocking REST endpoints and free and cheap API mock servers cover the next tier, and online API mocking tools compared puts the hosted options side by side.

When to move up to a real mock server

A schema-aware mock fixes every limitation above. This is where Apidog takes over from json-server.

Mock the same API in Apidog

  1. Download Apidog and create or open a project.
  2. Add an endpoint, for example GET /posts, and define its response schema (or import an existing OpenAPI file).
  3. Apidog generates a mock URL and starts returning smart, realistic data for every field right away.
  4. Need specific values? Add a mock rule per field to pin the output.
  5. Share the mock URL with your team or drop it into your test suite and CI.

You keep the “API in minutes” speed of json-server, and you gain validation, dynamic data, and a URL everyone can reach.

FAQ

Is json-server free? Yes, it’s open source and free to use. JSONPlaceholder is free too.

Does json-server persist data? Yes. POST, PUT, PATCH, and DELETE write back to your db.json, so changes survive between requests while the server runs. JSONPlaceholder fakes writes and saves nothing.

Can I use json-server in production? No. It’s built for prototyping and testing. It has no real validation, auth, or scalability story.

What’s the difference between json-server and a mock server like Apidog? json-server serves a static file as an API. Apidog mocks from your API schema, returns dynamic realistic data, and exposes a shared cloud URL. See what a mock API is and the REST mocking tools roundup for context.

How do I get realistic fake data instead of static rows? Use a generator. A test data generator creates varied, realistic records, and Apidog’s mock does this automatically from your schema.

The short version

json-server turns a JSON file into a working REST API with one command, and JSONPlaceholder gives you a hosted fake API with no setup at all. Both are perfect for getting unblocked fast. Once you need schema validation, dynamic data, persistent state, and a URL your team can actually reach, a flat file isn’t enough. That’s the line where Apidog’s mock server takes over. Download Apidog, import your spec, and your mock matches the real contract from the first request.

Explore more

Free Open-Source CLI Tools for API Management

Free Open-Source CLI Tools for API Management

Five free, open-source API management gateways you can run from the terminal: Kong OSS with decK, Tyk, KrakenD, Apache APISIX, and Gravitee, with real commands.

10 July 2026

How to Document APIs From the CLI

How to Document APIs From the CLI

Learn how to document APIs from the command line: build HTML with Redocly CLI, Markdown with Widdershins, then export live docs with the Apidog CLI in CI.

10 July 2026

How to Design APIs From the CLI

How to Design APIs From the CLI

Design APIs from the terminal: author OpenAPI, lint with Spectral, bundle with Redocly, generate stubs, then use the Apidog CLI for schemas and auth.

10 July 2026

Practice API Design-first in Apidog

Discover an easier way to build and use APIs

How to Build a Fake REST API in Minutes (with JSONPlaceholder)