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

paycomp-mock-server

v1.0.9

Published

A node mock server that does payload comparison to determine a response

Downloads

6

Readme

The Payload Comparison API Mocking Server

The Payload Comparision API mocking server is a Node.js web server that is designed to run locally in a terminal and provide a mock API endpoint for quick front end development and testing.

The server allows a user to configure one or more JSON based configuration files that can customise web-based API responses based on complex comparison of a request's path, headers, cookies and body, using regexp patterns.

Installation

To add the mocking server module to a project just run the following command from your projects root folder

npm install paycomp-mock-server@latest --sav-dev

Running the Server

Once the node module has been installed add the following script to you projects package.json file in the "scripts" list.

"scripts": { "api_server": "node './node_modules/paycomp-mock-server/launch.js'" }

Then all you need to do to run the server is run the following command in a terminal instance from your projects root folder.

npm run api_server

Server Configuration

Configuration of the server is achieved by creating one or more config.json files. There is a sample configuration available in the servers local node_modules folder (sample.config.json).

Server node

The server node allows you to set the tcp port of the server so that you can run several instances of server.

Verb Groups

The main configuration file can declare one or more of the four main http request methods (get, post, put and delete). All path configurations must exist under one of these verb groups.

Server Paths

All the different possible configurations of request and response exist as a declaration of a server path. A server path consists of:

  • A Path Pattern: This is a path-to-regex string pattern that tests a http request's path.
  • Header Patterns: This is a JSON object of properties that represent the headers that need to exist to validate the server path. With the value of each property being a regexp pattern string.
  • Cookie Patterns: In contrast to Header patterns, Cookie patterns are an array of JSON objects with a key, value and options property. These objects represent the cookies that need to exist to validate the server path. With the value, and options properties being regexp pattern strings.
  • Body Pattern: This is a single Regexp pattern used to test the value found in a requests body.
  • Response: This is the JSON object used to describe the construction of the http response object. The response object ust declare a numerical status value (e.g 200 or 404).
  • Response Headers: This is an object that allows the response to set the headers of the response based on the property names and values.
  • Response Cookies: This is an array of objects made up of key, value and option properties that allow the response to set cookies values. -Response Body: This can be one of three different types: a string value that is used to directly set the body payload: a faker object that is used to load JSON data with the faker service: a file object allows for the response to return a file thats available in project.

The Faker Service.

The Faker service allows for the creation of fake data by describing a JSON object using pre-defined entity types and properties, that are loaded with random data.