1.0.11 • Published 5 years ago

rest-mock-json v1.0.11

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

Mock JSON REST API Generator

This project is aimed to help UI developers create mock Express applications to allow for easier testing, and for setting up API calls to a server that may not exist yet. It is super easy to set up, and supports most use cases for hitting a REST API.

Usage

Global Install

Install the package globally

npm install -g rest-mock-json

Create a JSON file

Use the below shape to build out your mock api. Example Here

Run Server

rest-mock-json -f <path/to/your/json/filename.json>

You should be greeted with a few messages in the console, or errors pointing out what went wrong.

NPX

if you have npx, skip then installation step and run

npx rest-mock-json -f <path/to/your/json/filename.json>

Dev Dependency

This package can also be installed to your project and called from your package.json

npm install --save-dev rest-mock-json

{
    "scripts": {
        "mock-api": "rest-mock-json -f <path/to/your/json/filename.json>"
    }
}

JSON Shape

Optional values labelled.

{
  "port": number, // Port the app will listen on
  "baseUrl": string, // starts with "/"
  "notFound": any, // OPTIONAL 404 response
  "endpoints": [
    {
      "method": "GET", // GET | POST | PATCH | DELETE | PUT
      "path": string, // starts with "/"
      "shouldError": boolean, // OPTIONAL should respond with error response?
      "response": {
        "statusCode": number, // Status code for successful response
        "body": any // JSON response for success
      },
      "error": {
        "statusCode": number, // Status code for error response
        "body": any // JSON response for error
      }
    }
  ]
}

TODO

  • More dynamic responses
  • Test coverage
1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago