Skip to content
Easy to use, no frills http mock server
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
docs
examples
src
ssl
test
.eslintrc
.gitignore
.huskyrc
.prettierrc
CHANGELOG.md
LICENSE
README.md
SUMMARY.md
book.json
commitlint.config.js
package.json
yarn.lock

README.md

npm version build status coverage status dependency status devDependency status

mock-server

Easy to use, no frills http mock server.

Suppose you're developing a frontend app that talks to one or more API services. When running it locally - in your development environment - you need to somehow provide those services to the app: you can either rely on a remote deployment, start the services locally, or mock them.

mock-server is a command line tool that helps you take the third approach, allowing you to easily create and run a mock http server to run during development (and not only!).

Install

npm i --save-dev @staticdeploy/mock-server

Quickstart

  • create a directory mock-server
  • create your first handler file mock-server/get.js
    module.exports = (req, res) => res.send("OK");
  • start the mock server
    $ node_modules/.bin/mock-server
  • call the mocked route
    $ curl http://localhost:3456/

You add routes to the mock server by adding handler files at the corresponding path under the mock-server directory. Example:

mock-server
├── get.js -> handler for GET /
└── users
    ├── {userId}
    |   ├── get.js -> handler for GET /users/1
    |   └── put.js -> handler for PUT /user/1
    ├── get.js -> handler for GET /users
    └── post.js -> handler for POST /users

Documentation

You can’t perform that action at this time.