Mock Server

A fake server that simulates API responses for testing and development purposes.

A mock server is a simulated server that mimics the behavior of a real API. It allows developers to test their applications without relying on actual backend services.

Why Use a Mock Server?

  • Parallel Development: Frontend teams can work independently while backend is being built
  • Reliable Testing: Get consistent responses without network issues or rate limits
  • Cost Savings: Avoid charges from third-party APIs during development
  • Edge Case Testing: Easily simulate errors, timeouts, and unusual scenarios

Popular Mock Server Tools

  • JSON Server - Quick REST API from a JSON file
  • MSW - Mock Service Worker for browser and Node.js
  • WireMock - Enterprise-grade mocking for Java
  • Mockoon - Desktop app with GUI
  • Prism - Auto-generate mocks from OpenAPI specs

Code Examples

JSON Server Setup

npx json-server --watch db.json --port 3001

Express Mock Server

const express = require("express");
const app = express();

app.get("/api/users/:id", (req, res) => {
  res.json({ id: req.params.id, name: "John Doe" });
});

app.listen(3001);