Intro

This tutorial will teach you the fundamentals of mocking out any HTTP API with Mirage. While Mirage can be used to mock out GraphQL APIs, this tutorial will cover a basic REST API.

You'll learn Mirage by mocking out the API for a Reminders app. The app is written in React, but you don't need to know React to follow along since you'll only be writing Mirage code.

There is no real API server running, so the app doesn't work to start. As you implement each API endpoint, you'll be restoring the functionality of the app.

Here's an example of the final result:

mirage-tutorial.vercel.app (source)

Setup

First let’s get your development environment ready. You'll need Node.js installed, and you'll be using your own text editor and terminal app.

Next, download the tutorial and install its dependencies:

npx degit github:miragejs/tutorial mirage-tutorial
cd mirage-tutorial
yarn install

# You can also use npm:
npm install

Then open the project in your editor and start your app:

yarn start

# or npm run start

This should run a development server on port 3000.

Open http://localhost:3000 in your browser and you should see a page that looks like this:

Reminders app

If you do, you're ready to start mocking!