JanLoebel / simplest-mock-server

This is a very simple mock server. Simplify returning static data on http requests.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simplest Mock Server

Build Status

This is a very simple mock server. Simplify returning static data on http requests.

It supports returning different static files requested with a specific url, method or query-parameters.

Return mock data specified by:

  • url (e.g.: /customer )
  • method (e.g.: GET, POST)
  • query-parameter (e.g.: ?page=2&sort=name,desc)

Using the server

  1. Navigate into your MagicMirror's modules folder and execute git clone https://github.com/JanLoebel/simplest-mock-server.git
  2. Execute cd simplest-mock-server && npm install to install the node dependencies
  3. Start the server by executing npm run watch
  4. Configure the routes depending on your needs. Therefore open the config.js
module.exports = {
  server: {
    port: 3000
  },
  mocks: [
    {
      path: "/test",
      query: "a=true&b=false&c=1",
      responseFile: "./responseFiles/test1.txt",
    },
    {
      path: "/test/2",
      responseFile: "./responseFiles/test2.json"
      method: "POST",
      responseCode: 200
    }
  ];
}

Running the tests

Simplest Mock Server comes bundled with a Postman Collection containing some tests to verify everything is working.
It is run using Newman. These tests are based on the default response files.

Run the tests with:

npm test

Configuration options

Option Description
server Required Server configuration, see Server configuration options.

Type: object
mocks Required Array of mocks, see Mock configuration options.

Type: array

Server configuration options

Option Description
port Optional Server port to listen.

Type: int
Default: 3000

Mock configuration options

Option Description
path Required Path to listen for requests.

Type: string
method Optional HTTP-Method to listen for.

Type: string
Default: GET
query Optional Query-String to match, order is not important.

Type: string
responseFile Optional Location for the file to return.

Type: string
responseCode Optional Response-Code to return.

Type: int
Default: 200

Contribution

Please feel free to improve or modify the code and send a Pull-Request! Any contribution is very welcome :)

The MIT License (MIT)

Copyright © 2018 Jan Loebel

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

The software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.

About

This is a very simple mock server. Simplify returning static data on http requests.

License:MIT License


Languages

Language:JavaScript 98.7%Language:HTML 1.3%