Giter Site home page Giter Site logo

itsvinayak / mock-crud-api Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 1.02 MB

This package allows you to create mock REST API servers for testing and development purposes. It provides a simple and convenient way to define server configurations, handle requests, and send mock responses.

License: MIT License

JavaScript 100.00%
api-mocking api-rest api-testing mock nodejs testing

mock-crud-api's Introduction

mock-crud-api

This package allows you to create mock REST API servers for testing and development purposes. It provides a simple and convenient way to define server configurations, handle requests, and send mock responses.

MOCKAPIIMAGE

NodeJS NPM Node.js Lint and Uts npm GitHub last commit (branch)

Features

  • Define server configurations with port, path, request type, input, output, and error handling options.
  • Handle HTTP requests.
  • Compare request input with predefined input to determine the response.
  • Customize response outputs and error codes.
  • Parse query strings and extract parameters.
  • Validate and ensure required data fields are present.
  • Start multiple servers simultaneously using a configuration file.
  • Display helpful information and syntax examples.

Installation

To install the mock-crud-api package, follow these steps:

  • Make sure you have Node.js installed on your machine.
  • Open a terminal or command prompt.
  • Navigate to your project directory.
  • Run the following command to install the package:
npx mock-crud-api --config config.json
npx mock-crud-api -c config.json

Usage

To use the mock-crud-api package, follow these steps:

  • Create a configuration file (e.g., config.json) with the server configurations.
[
    {
        "name": "post-server",
        "method": "POST",
        "port": 3000,
        "path": "/",
        "input": {
            "method": "text"
        },
        "code": 200,
        "output": "text",
        "errorCode": 500,
        "errorMessage": "Internal Server Error"
    },
    {
        "name": "get-server-1",
        "method": "GET",
        "port": 3001,
        "path": "/test",
        "input": null,
        "code": 200,
        "output": "text"
    },
    {
        "name": "get-server-2",
        "method": ["GET"],
        "port": 3002,
        "path": "/test",
        "input": {},
        "code": 201,
        "output": "text"
    },
    {
        "name": "patch-server-3",
        "method": ["PATCH", "PUT"],
        "port": 3003,
        "path": "/test",
        "input": {
            "method": "json"
        },
        "code": 201,
        "output": "Updated",
        "errorCode": 500,
        "errorMessage": "Internal Server Error"
    }
]

In the configuration file, you can define multiple server configurations. Each configuration object should have the following properties:

  • name: The name of the server.
  • type: The HTTP request method (e.g., GET, POST, PUT, DELETE).
  • port: The port number on which the server will listen.
  • path: The API endpoint path for the server.
  • input: The input for which the output is to be generated.
  • code: Code if server found successfully
  • output: The output to be generated for matching requests.
  • errorCode: The error code to be returned if the server is not found.
  • errorMessage: The error message to be returned if the server is not found.

License GitHub

This package is released under the MIT License.

mock-crud-api's People

Contributors

itsvinayak avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

pratishthan

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.