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

json-api-mocker

v3.0.0

Published

A mock server with visual management interface

Downloads

1,403

Readme

JSON API Mocker

A lightweight and flexible mock server with JSON configuration and visual management interface.

✨ Features

  • 🚀 Brand new visual management interface
  • 🚀 Support both configuration file and UI management
  • 🔄 Support all common HTTP methods
  • 📝 Automatic data persistence
  • 🔍 Built-in pagination support
  • 🛠 Customizable response structure
  • 🎭 Powerful data mocking with Mock.js
  • 📊 Real-time request logs and statistics
  • 💡 TypeScript support

📦 Installation

npm install -g json-api-mocker

🚀 Quick Start

The server uses fixed ports:

  • API Server: 35728
  • Web UI: 35729
  • WebSocket: 35730

Method 1: Using Visual Interface (Recommended)

  1. Create a data.json file:
{
  "server": {
    "port": 35728,
    "baseProxy": "/api"
  },
  "routes": []
}
  1. Start the server:
# Start server and open browser
json-api-mocker -o

After starting, the browser will automatically open the management interface, where you can:

  1. Visually create and manage APIs
  2. View real-time request logs
  3. Monitor API call statistics
  4. Debug mock data online

Method 2: Using Configuration File (Compatible with old version)

Create a data.json file:

{
  "server": {
    "port": 8080,
    "baseProxy": "/api"
  },
  "routes": [
    {
      "id": "user-api",
      "route": {
        "path": "/users",
        "methods": {
          "get": {
            "status": 200,
            "response": {
              "code": 200,
              "message": "success",
              "data": {
                "list|10": [{
                  "id": "@id",
                  "name": "@name",
                  "email": "@email"
                }]
              }
            }
          }
        }
      }
    }
  ]
}

Then start the server:

json-api-mocker

📖 Configuration

Server Configuration

{
  "server": {
    "port": 8080,      // Server port
    "baseProxy": "/api" // API base path
  }
}

API Configuration

Each API configuration includes:

{
  "id": "unique-id",    // API unique identifier
  "route": {
    "path": "/users",   // API path (without base path)
    "methods": {        // Supported HTTP methods
      "get": {
        "status": 200,  // Response status code
        "headers": {    // Custom response headers
          "Content-Type": "application/json"
        },
        "response": {   // Response data (supports Mock.js syntax)
          "code": 200,
          "data": {
            "name": "@name",
            "age": "@integer(18, 60)"
          }
        }
      }
    }
  }
}

🎮 Visual Interface Features

1. API Management

  • Create, edit, and delete APIs
  • Support multiple HTTP methods
  • Visual response data editor
  • Mock.js syntax hints

2. Real-time Logs

  • Request path and method
  • Response status and duration
  • Request parameters recording
  • Response data viewing

3. Statistics Dashboard

  • Total API count
  • Request volume monitoring
  • Average response time
  • Success rate statistics

🔧 Command Line Options

json-api-mocker [options]

Options:
  -p, --port <number>     Specify server port (default: 8080)
  -c, --config <path>     Specify config file path (default: data.json)
  -o, --open             Auto open management interface
  -h, --help            Show help information
  -v, --version         Show version number

📄 License

MIT © [Xiong Haiyin]

🙏 Acknowledgments

  • Thanks to all contributors and users
  • Special thanks to Mock.js for data mocking support