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.
Mock Server
A fake server that simulates API responses for testing and development purposes.
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 3001Express 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);Related Terms
API Mocking
Simulating API behavior to enable development and testing without real backend services.
Read more
WebSocket
A protocol enabling full-duplex, real-time communication between client and server.
Read more
HTTP Status Codes
Standard response codes that indicate the result of an HTTP request.
Read more
Latency
The time delay between a request being sent and a response being received.
Read more