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

mockapi-msi

v2.0.1

Published

Mock API is a lightweight configurable HTTP API for testing and prototyping.

Downloads

2

Readme

Dynamic mocking descriptive API (MockAPI)

MockAPI help you buiding your app when requires connecting to a not yet built external API.

MockAPI let you create fake responses with pre defined and dynamic data for defined endpoints.

MockAPI also is intended to help you when, during testing phase, you cannot afford complex and expensive products (And you do not need them) that requires bulky configuration steps or depends directly on third party providers that you cannot control.

Version 2.0.1 notes

  • A bug related to custom handlers was detected and fixed.

Version 2.0.0 notes

  • Using NodeJS managers such as NVM causes configuration file not being picked from the execution/working folder.
  • New CORE class created and code moved from the main module.
  • Additional checking for the configuration file.
  • Folder file readear incorrect path contactenation fixed.

Configuration file

MockAPI can be used as it is. Without any additional coding activity. Just configure your endpoints and run main.js file.

Configuring MockAPI

Edit .mockapi-config to add your own endpoints, responses, parsers and data. Use standard YAML notation for this file.

Main entry points

port - Specify the HTTP port to be used by MockAPI to expose the defined endpoints.

enableCors - Enable/Disable CORS for MockAPI.

externalModulesPath - Optional configuration. Allows to specify a different path where the user custom handlers are located.

data - Holds and describe the available data for all endpoints and responses.

endpoints - Describe all available endpoints, its verbs and responses.

log - Define MockAPI log level.

customHandlers - Import a custom HTTP data handler. Use these custom handlers to manipulate the output of your responses for a particular endpoint.

Within data entry, it is possible to define how the data must be handled. There are three built-in readers that comes with MockAPI.

csv - Reads the defined data as CSV.

text - Considers the data source as plain text.

folder - Reads the files from the folder matching the incoming request name.

Data definition

myRows:
    path: "./testdata/data.csv"
    reader: csv
    properties: 
      - json
      - seq
      - 0

The previous example defines a data source called myRows, which will read the data from the defined path, using the csv handler, parsing each row as json, reading the values in a sequential order, starting from record 0.

Endpoint definition

"/users":
  verb: get
  data: myRows
  responseStatus: 200
  responseContentType: "application/json"

From the previous code snippet, we are defining an endpoint [MockAPI URL]:[PORT]/users, which will accept get requests, answering always with 200 status code, using data from myRows data definition in JSON format.

Custom handlers

A custom handler let you manipulate the data as your will. First, define the handler as follows:

customHandlers:
  "custom": 
    "myCustomHandler"

The previous code defines a custom handler called custom and will use the script code called myCustomHandler. The custom code must be placed inside of scripts folder and coded in JavaScript with NodeJS support.

Your custom script must implement the following export format:

module.exports = {
    process: [Your function entry point]
};

Setting up the log level

MockAPI logs information into the execution console. There are different levels of logs that can be used.

log: verbose
  #debug <- Useful for custom handlers
  #error <- Only exposes internal errors
  #verbose <- Logs debug, information and errors
  #none <- Turn off the logs

MockAPI CLI

MockAPI provides a small but helpful CLI. Type mockapi --help to get the available commands from the CLI once MockAPI is installed.

The init command

Once MockAPI is globally installed, you will need a configuration file with minimal information to be able of start mocking the API. The init command argument will lead you through different basic questions helping you to initialize this configuration file.

mockapi --init

You can skip every question which will assign some default values to the configuration file. Later you could change these values using any text editor.