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

pokemock

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pokemock

A mock server generated from one or more arbitrary Swagger files. Supports seeding, timeouts, response picking, entity memory, semantic action inference, etc.

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15
decreased by-37.5%
Maintainers
3
Weekly downloads
 
Created
Source

Pokemock

A mock server generated from one or more arbitrary Swagger files. Supports seeding, timeouts, response picking, entity memory, semantic action inference, etc.

Usage

Syntax:
  pokemock <swagger-urls-or-files> ... [-h] [-v] [-w] [-p <port>]

Options:
  -h, --help        Show help
  -v, --version     Show version
  -p, --port <port> Set server port, default is 8000
  -w, --watch       Watch mode: Restart on Swagger changes
  -k, --killable    Publish /kill endpoint to stop the service
      --memory      Enable memory module (experimental)

Server

The mock server listens to the specified port and mocks endpoints defined in the provided Swagger document. Additionally, it publishes a Swagger UI under /ui, the Swagger API under /api-docs and a /kill endpoint for shutdown.

Request Headers

Using optional headers, clients can control the server's behavior:

  • X-Mock-Status
    • Specifies the response status code
    • The correct response is inferred from the API if possible
    • Defaults to the first response code specified in the API
  • X-Mock-Seed
    • Specifies a seed for data generation
    • If omitted, a random seed is generated
    • The current seed is always returned in a X-Mock-Seed response header
  • X-Mock-Time
    • Specifies the minimum response time (milliseconds)
  • X-Mock-Size
    • Specifies array size(s) in the response
    • Must be a valid JSON object of <definitionName|attributeName>: <size> pairs
    • If omitted, array sizes are randomly between 1 and 5
  • X-Mock-Depth
    • Specifies the maximum JSON data depth
    • Defaults to 5
  • X-Mock-Override
    • Specifies response data via JSON Path
    • Must be a valid JSON object of <jsonPath>: <data> pairs
    • <data> is arbitrary JSON
  • X-Mock-Replay
    • Specifies the number of times the current X-Mock-* headers should be replayed
    • The next N requests to the requested URL will replay the current X-Mock-* headers
  • X-Mock-Replay-Pattern
    • Specifies a regular expression to match for X-Mock-Replay
    • If omitted, the exact path is used for replaying

Memory (experimental)

Use the --memory switch to enable the memory module. When enabled, entities containing an ID are remembered by the server. If the entity is requested again, the remembered data is returned. This also applies to sub-entities across endpoints.

Additionally, the server tries to infer semantic actions from requests, such as:

  • Get by id
  • Delete by id
  • Update by id
  • Create new entity

These actions are applied to known entities in memory. For example, requesting a deleted entity will result in a 404 response.

Customization

Pokemock provides a set of Express middlewares which you can use independently. The default app defined in createDefaultApp.js is an opinionated stack of middlewares which you're encouraged to hack on. By re-arranging and adding middlewares (especially generators) you can tailor Pokemock to fit your APIs.

FAQs

Package last updated on 26 Apr 2017

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