Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

puremock

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

puremock

A zero-dependency node mock api server

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Puremock

⚡️ A zero-dependency mock api server ⚡️

Built with ❤︎ by orels1

Motivation

Hacktoberfest, mainly, but also just a search for a package like this that took me more than an hour and ultimately pointed me to Mockoon (which is great, btw, check it out). But I figured I should make this too, since I have a soft spot for cute zero-dep tools, so here we are. Hope you'll enjoy using it as much, as I did developing it.

Installation

# with npm
npm i -g puremock

#with yarn
yarn global add puremock

Usage

Create a mock file

By default puremock will look for mockApi.json in the project root. But you can also supply a different path (see below).

{
  "GET /": {
    "response": {
      "status": "ok"
    }
  },
  "GET /error": {
    "status": 503,
    "header": {
      "x-powered-by": "mock-api-server"
    },
    "response": {
      "error": "Internal Server Error"
    }
  },
  "GET /articles/:name": {
    "response": {
      "title": "Foobar"
    }
  }
}

That's about it as far as configuration goes. You can supply any kind of HTTP method, set response codes and headers.

Path params are supported (with multiple levels), so you can have endpoints like /root/:param1/:param2 or /root/exact/:param1 and so on. Useful when you have a bunch of dynamic IDs your app requests, but you don't care if the same thing is being returned.

Check example.json for references.

Default response code is 200, and the Content-Type header is set to application/json.

Start the server

By default the server will start at localhost:3000.

# uses a mockApi.json in the project root
puremock

# you can pass a custom path to a mock file
puremock ./mocks/api.json

# port customization is also supported
puremock --port 4000

Contribute

There are still things we can add while staying lightweight and zero-dependency:

  • Add a mock file hot-reload
  • Support for dynamic urls (i.e. `/posts/:id)
  • Add a set of prebuilt error responses so users can just supply `status: 503) to get a meaningful response object without defining it
  • Improve the watcher logic (it fails from time to time so I have a bunch of retries there)

The package is auto-published with the latest tag in the package.json when merged into master.

FAQs

Package last updated on 29 Oct 2018

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