New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mockifyjs

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockifyjs

A Server Mocker for creating temperary rest api servers.

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

MockifyJS

MockifyJS is an npm package that allows you to quickly create a mock server by using a very easy to learn and understand syntax.

Install

MockifyJS can be installed with npm using the command below.

npm i -g mockifyjs

Usage

After Installing MockifyJS,
Create a mocker file server.mkr,
and run your mocker file with the command

mockify server.mkr

Which will run the mocker file on the default Port 3000
You can change this by passing the port too.

mockify server.mkr 5000

Modifying a mocker file after runing the mocker server will make the changes take place instantly,
Which means you dont have to restart the mocker server everytime you modify the mocker file.

Syntax

The Mocker Syntax is very easy to understand and learn.
This is a basic mocker file syntax.

alt="MockifyJS"

A Mocker File has a Request Method which could be any of this.

  • GET - a GET request
  • POST - a POST request
  • PUT - a PUT request
  • DELETE - a DELETE request
  • HEAD - a HEAD request
  • OPTIONS - a OPTIONS request
  • TRACE - a TRACE request
  • CONNECT - a CONNECT request
  • ALL - any type of request

Request Path

The Request Path is the Request Path of a request.
Eg api/v2/user,password/forgot,etc

When any request to the mocker server matches the Request Method and Request Path,
The Response Headers and Response Text is returned.
If the request does not match any request in the mocker file, a 404 error occurs.

Tags

Mocker Tags are special words in MockifyJS which starts with a $,
We use these Tags in The Response Text to return a special type of response.

alt="MockifyJS"

echo

The echo Tag simply returns the Request Data as the Response Text,
Which means it gives you back what you give it.

POST /api 200
    Content-Type: application/json
$echo

randNumber

The randomNumber Tag takes a number and returns a random number between 0 and the number passed to it.

POST /random 200
    Content-Type: application/json
$randNumber 100

get

The get Tag takes a url and makes a get request to this url and retun the response as Response Text

POST /get/example 200
$get https://example.com

readFile

The readFile Tag reads a file from the file system and return it as the Response Text
This can be used to return a media or any other type of file.
This is an example of an image file.

GET /images/cat.jpg 200
    Content-Type: image/jpeg
$readFile ../../Downloads/cat.jpg

MockifyJS was made with ❤️ in 🇳🇬 by Dev Bash

Keywords

FAQs

Package last updated on 04 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc