paycomp-mock-server

1.0.9 • Public • Published

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.

Package Sidebar

Install

npm i paycomp-mock-server

Weekly Downloads

4

Version

1.0.9

License

MIT

Unpacked Size

230 kB

Total Files

92

Last publish

Collaborators

  • grumpycodemonkey