Esta página se muestra en inglés. Una traducción al español está en curso.
ScriptsJul 25, 2026·3 min de lectura

Mirage.js — Client-Side API Mock Server for Frontend Development

A client-side server that intercepts network requests, enabling frontend developers to build, test, and prototype without a real backend.

Listo para agents

Staging seguro para este activo

Este activo primero queda en staging. El prompt copiado pide inspeccionar los archivos staged antes de activar scripts, config MCP o config global.

Stage only · 27/100Política: staging
Superficie agent
Cualquier agent MCP/CLI
Tipo
CLI Tool
Instalación
Single
Confianza
Confianza: Established
Entrada
Mirage.js Overview
Comando de staging seguro
npx -y tokrepo@latest install 3387d421-8869-11f1-9bc6-00163e2b0d79 --target codex

Primero deja archivos en staging; la activación requiere revisar el README y el plan staged.

Introduction

Mirage.js runs a mock server entirely in the browser by intercepting fetch and XMLHttpRequest calls. It provides a full data layer with models, relationships, factories, and serializers, letting frontend teams develop and test against a realistic API without backend dependencies.

What Mirage.js Does

  • Intercepts HTTP requests in the browser and returns configured responses
  • Provides an in-memory database (Mirage DB) with ORM-like models and relationships
  • Generates test data via factories and the Faker-powered seed system
  • Simulates network latency and error responses for edge case testing
  • Supports passthrough routes to forward certain requests to a real server

Architecture Overview

Mirage.js patches the global fetch and XMLHttpRequest constructors to route matching requests through its handler pipeline. Route handlers interact with an in-memory database backed by a schema of models and relationships. Serializers transform database records into API response formats (JSON:API, REST, or custom).

Self-Hosting & Configuration

  • Install via npm and create a server in your app entry point
  • Define models and relationships in the server config for the ORM layer
  • Create factories for generating realistic seed data
  • Use timing option to simulate network latency during development
  • Disable or passthrough routes when connecting to a real backend

Key Features

  • Full ORM with hasMany, belongsTo, and polymorphic relationships
  • Factory system for generating large datasets with realistic attributes
  • Serializer layer supporting JSON:API, Active Model, and custom formats
  • Route shorthands that auto-generate CRUD endpoints from models
  • Works with any frontend framework: React, Vue, Angular, Svelte

Comparison with Similar Tools

  • MSW (Mock Service Worker) — Intercepts at the service worker level; Mirage.js includes a data layer
  • JSON Server — File-based REST mock; Mirage.js runs in-browser with an ORM
  • Polly.js — Records real API responses; Mirage.js builds mock responses from scratch
  • Nock — Node.js-only HTTP mocking; Mirage.js runs in the browser
  • WireMock — Java mock server; Mirage.js needs no separate process

FAQ

Q: Does Mirage.js work in production? A: It is designed for development and testing. Disable or remove it before deploying to production.

Q: Can I use it alongside a real API? A: Yes. Use this.passthrough() for routes you want to forward to the actual backend.

Q: Does it support GraphQL? A: Not natively, but you can define custom route handlers that parse GraphQL queries and return data from the Mirage DB.

Q: How do I seed the database with initial data? A: Use the seeds(server) hook in the server config to call server.create() with your factories.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados