Code Monkey home page Code Monkey logo

mockayo's Introduction

Mockayo - simple HTTP mock server

screenshot 2019-02-16 at 19 21 16

Set up

Install the package as a devDependency:

npm install mockayo --save-dev

Create a JavaScript config file with any name, with the following structure:

module.exports = {
  baseDirectory: '[PATH TO YOUR DIRECTORY WITH MOCK SCENARIOS]',
  port: [PORT TO RUN THE MOCK SERVER ON], // defaults to 8000,
  mocks: [
    {
      name: '[ENDPOINT NAME - WILL BE DISPLAYED IN CONTROL UI]',
      method: '[ENDPOINT METHOD]',
      url: '[ENDPOINT URL]',
      directory: '[SUBDIRECTORY WITH SCENARIOS (UNDER BASE DIRECTORY)]',
    },
    // ... define as many mocks as you wish ...
  ]
};

For each mock (combination of URL and method), create a directory with at least one scenario, called default.js. You can create as many as you want though. Each scenario should be a regular JavaScript file, exporting an object with the following structure:

module.exports = {
  code: [HTTP RESPONSE CODE], // defaults to 200
  body: [HTTP RESPONSE BODY - STRING OR JAVASCRIPT OBJECT (NOT SERIALIZED)],
}

Check out an example of the config file and mock scenarios.

Finally, add a command to your package.json:

  "scripts": {
    // ... your scripts ...
    "mock-server": "mockayo [RELATIVE/ABSOLUTE PATH TO YOUR CONFIG FILE]"
  },

Now, you can run your mock server, using the following command:

npm run mock-server

When the server is running, you can make all calls you defined in the config, as well as access the control UI to switch scenarios.

mockayo's People

Contributors

marcin-mazurek avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.