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

pokemock

v1.2.0

Published

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

Downloads

63

Readme

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.