npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mock-crud-api

v1.0.6

Published

mock crud api for testing

Downloads

14

Readme

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 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.