Convert Figma logo to code with AI

Kong logoinsomnia-mockbin

Insomnia Mockbin is the underlying backend for the API mocks capability of Insomnia. It is built and used by Kong, the author of the open-source Kong Gateway.

2,034
213
2,034
43

Top Related Projects

12,762

HTTP Request & Response Service, written in Python + Flask.

Get a full fake REST API with zero coding in less than 30 seconds (seriously)

12,708

HTTP server mocking and expectations library for Node.js

Over the wire test doubles

15,796

Seamless REST/GraphQL API mocking library for browser and Node.js.

Quick Overview

Insomnia Mockbin is an open-source HTTP request and response service designed for testing and mocking API endpoints. It allows developers to create custom endpoints, inspect HTTP requests, and generate mock responses, making it an invaluable tool for API development and testing.

Pros

  • Easy to set up and use, with a user-friendly interface
  • Supports a wide range of HTTP methods and custom response types
  • Provides detailed request inspection and logging capabilities
  • Can be self-hosted or used as a cloud service

Cons

  • Limited documentation and community support compared to some alternatives
  • May require additional configuration for complex use cases
  • Lacks some advanced features found in paid API mocking tools
  • Potential security concerns when using the public cloud version for sensitive data

Code Examples

// Creating a new mock endpoint
const mockbin = require('mockbin');

const endpoint = mockbin.create({
  method: 'GET',
  path: '/api/users',
  response: {
    status: 200,
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ users: ['Alice', 'Bob', 'Charlie'] })
  }
});

console.log(`Mock endpoint created: ${endpoint.url}`);
// Inspecting a request
const mockbin = require('mockbin');

mockbin.on('request', (req) => {
  console.log('Received request:');
  console.log(`Method: ${req.method}`);
  console.log(`Path: ${req.path}`);
  console.log(`Headers: ${JSON.stringify(req.headers)}`);
  console.log(`Body: ${req.body}`);
});
// Generating a dynamic response
const mockbin = require('mockbin');

mockbin.create({
  method: 'POST',
  path: '/api/data',
  response: (req) => {
    const data = JSON.parse(req.body);
    return {
      status: 201,
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ id: Date.now(), ...data })
    };
  }
});

Getting Started

To get started with Insomnia Mockbin, follow these steps:

  1. Install Mockbin:

    npm install mockbin
    
  2. Create a new JavaScript file (e.g., server.js) and add the following code:

    const mockbin = require('mockbin');
    const port = 3000;
    
    mockbin.createServer().listen(port, () => {
      console.log(`Mockbin server running on port ${port}`);
    });
    
  3. Run the server:

    node server.js
    
  4. Access the Mockbin interface at http://localhost:3000 to create and manage mock endpoints.

Competitor Comparisons

12,762

HTTP Request & Response Service, written in Python + Flask.

Pros of httpbin

  • More comprehensive set of endpoints for testing various HTTP scenarios
  • Longer project history and wider community adoption
  • Better documentation and examples available

Cons of httpbin

  • Less focus on mocking specific API responses
  • Fewer customization options for response content
  • Not as tightly integrated with a specific API development tool

Code Comparison

httpbin:

@app.route('/ip')
def ip_address():
    return jsonify(origin=request.headers.get('X-Forwarded-For', request.remote_addr))

insomnia-mockbin:

app.get('/ip', (req, res) => {
  res.json({ ip: req.ip });
});

Both projects provide similar functionality for returning the client's IP address, but httpbin uses Python with Flask, while insomnia-mockbin uses JavaScript with Express.

httpbin offers a more extensive range of endpoints and scenarios, making it suitable for general HTTP testing. insomnia-mockbin, on the other hand, is more focused on mocking API responses and integrates well with the Insomnia API client.

httpbin has been around longer and has a larger user base, which contributes to its stability and community support. However, insomnia-mockbin's tight integration with Insomnia may make it more appealing for users of that specific tool.

While httpbin provides a wide array of predefined endpoints, insomnia-mockbin offers more flexibility in creating custom mock responses, which can be advantageous for specific API testing scenarios.

Get a full fake REST API with zero coding in less than 30 seconds (seriously)

Pros of json-server

  • Simpler setup and usage, ideal for quick prototyping
  • Supports full REST API operations (GET, POST, PUT, PATCH, DELETE)
  • Allows custom routes and middlewares for more flexibility

Cons of json-server

  • Limited to JSON data only, less versatile than insomnia-mockbin
  • Lacks advanced features like request inspection and custom response headers

Code Comparison

insomnia-mockbin:

const mockbin = require('mockbin');
const server = mockbin();
server.listen(8080, () => {
  console.log('Mockbin is running on port 8080');
});

json-server:

const jsonServer = require('json-server');
const server = jsonServer.create();
const router = jsonServer.router('db.json');
server.use(router);
server.listen(3000, () => {
  console.log('JSON Server is running on port 3000');
});

Key Differences

  1. Purpose: insomnia-mockbin is designed for API testing and debugging, while json-server focuses on creating mock REST APIs quickly.
  2. Data handling: insomnia-mockbin supports various data formats, whereas json-server is limited to JSON.
  3. Features: insomnia-mockbin offers more advanced features like request inspection and custom headers, while json-server provides a simpler, more straightforward approach to mocking APIs.
  4. Setup complexity: json-server is generally easier to set up and use for basic mock API needs, while insomnia-mockbin offers more advanced capabilities at the cost of increased complexity.

Both tools serve different purposes and can be valuable depending on the specific requirements of your project.

12,708

HTTP server mocking and expectations library for Node.js

Pros of nock

  • More lightweight and focused on HTTP mocking for Node.js applications
  • Extensive API for fine-grained control over request matching and response generation
  • Supports chaining of interceptors for complex request/response scenarios

Cons of nock

  • Limited to Node.js environment, not suitable for browser-based testing
  • Steeper learning curve due to its more comprehensive API
  • Lacks built-in UI for request inspection and response manipulation

Code Comparison

nock:

const scope = nock('https://api.example.com')
  .get('/users')
  .reply(200, { users: [{ id: 1, name: 'John' }] });

insomnia-mockbin:

const mockbin = require('mockbin');
mockbin.createBin({
  httpResponse: {
    status: 200,
    body: JSON.stringify({ users: [{ id: 1, name: 'John' }] })
  }
});

Key Differences

  • nock is primarily used for programmatic HTTP mocking in Node.js tests
  • insomnia-mockbin provides a full-featured mock HTTP server with a web interface
  • nock offers more granular control over request matching and response generation
  • insomnia-mockbin is better suited for manual API testing and exploration
  • nock integrates seamlessly with Node.js testing frameworks
  • insomnia-mockbin can be used as a standalone service for various HTTP-related tasks

Both tools serve different purposes and can be complementary in a developer's toolkit, depending on the specific testing and mocking needs of a project.

Over the wire test doubles

Pros of Mountebank

  • More versatile with support for multiple protocols (HTTP, HTTPS, TCP, SSH)
  • Offers advanced features like stubbing, mocking, and proxying
  • Provides a powerful JavaScript API for complex scenarios

Cons of Mountebank

  • Steeper learning curve due to more complex configuration
  • Requires more setup and configuration compared to Insomnia-mockbin
  • May be overkill for simple API mocking needs

Code Comparison

Mountebank configuration example:

{
  "port": 4545,
  "protocol": "http",
  "stubs": [{
    "responses": [{ "is": { "statusCode": 200, "body": "Hello, World!" } }]
  }]
}

Insomnia-mockbin usage example:

const mockbin = require('mockbin');
mockbin.createServer().listen(3000, () => {
  console.log('Mockbin server is running on port 3000');
});

Summary

Mountebank offers more advanced features and protocol support, making it suitable for complex mocking scenarios. However, it comes with a steeper learning curve and requires more setup. Insomnia-mockbin, on the other hand, provides a simpler solution for basic API mocking needs, with easier setup and usage. The choice between the two depends on the specific requirements of your project and the level of complexity you need in your mocking environment.

15,796

Seamless REST/GraphQL API mocking library for browser and Node.js.

Pros of msw

  • Integrates seamlessly with modern JavaScript testing frameworks
  • Supports both REST and GraphQL APIs
  • Allows for more realistic mocking by intercepting network requests at the network level

Cons of msw

  • Steeper learning curve for developers new to service workers
  • Requires additional setup for browser-based testing environments

Code Comparison

msw:

import { rest } from 'msw'
import { setupServer } from 'msw/node'

const server = setupServer(
  rest.get('/api/user', (req, res, ctx) => {
    return res(ctx.json({ name: 'John Doe' }))
  })
)

insomnia-mockbin:

const mockbin = require('mockbin')

mockbin.createBin({
  method: 'GET',
  path: '/api/user',
  response: {
    status: 200,
    body: JSON.stringify({ name: 'John Doe' })
  }
})

Key Differences

  • msw uses a service worker approach, while insomnia-mockbin creates actual endpoints
  • msw offers more flexibility in request interception and response manipulation
  • insomnia-mockbin provides a simpler setup for basic mocking scenarios

Use Cases

  • msw: Ideal for complex frontend testing and development environments
  • insomnia-mockbin: Better suited for quick API mocking and simple backend simulations

Community and Maintenance

  • msw has a larger and more active community on GitHub
  • insomnia-mockbin is part of the Kong ecosystem, which may provide enterprise support

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Insomnia Mockbin version License

Note: This repository is source visibile, but not open-source. Please check the LICENSE before using this software.

Insomnia Mockbin is maintained by Kong, who also maintains the open-source API Gateway Kong and Insomnia.

Table of contents

Features

  • uses HAR format
  • supports JSON, YAML, XML, HTML output
  • plays nice with proxies (uses the X-Forwarded-* headers for IP resolution)
  • allows for HTTP Method Override using the header X-HTTP-Method-Override or through query string parameter: _method
  • create custom bins for experimenting log collection

Installation

Requirements

brew install redis
brew services start redis

Redis should be now running on localhost:6379 Mockbin will start without redis but you wont be able to set or get response bins.

git clone https://github.com/Kong/mockbin.git ./mockbin
cd mockbin
cp .env.sample .env
brew install fnm
fnm use
npm install

Note: nvm, n or volta can be used instead of fnm.

Running with Node

npm start
# OR watch for changes
npm run dev
# OR with debug logs
DEBUG=mockbin npm run dev

Running with Docker Compose

docker compose up

Documentation

API Docs

Read the full API documentation, please review the API Docs.

Releasing

Run the following command and push the newly created commit into your PR. This will bump commit and tag, you will need to push this to the remote, which trigger the release action upon merging the PR.

npm version patch
git push origin tag <tag_name>

Software Bill of materials

Kong Insomnia Mockbin produces SBOMs for the below categories:

  • For docker container images
  • For source code repository

The SBOMs are available to download at:

  • Github Release / Tag Assets
  • Github workflow assets for other workflow runs

Verify a container image signature

Docker container images are now signed using cosign with signatures published to a Github Container registry with insomnia-mockbin repository.

Steps to verify signatures for signed Kong Insomnia Mockbin Docker container images in two different ways:

A minimal example, used to verify an image without leveraging any annotations. For the minimal example, you only need Docker details, a GitHub repo name, and a GitHub workflow filename.

cosign verify \
  ghcr.io/kong/insomnia-mockbin:<tag>@sha256:<digest> \
  --certificate-oidc-issuer='https://token.actions.githubusercontent.com' \
  --certificate-identity-regexp='https://github.com/Kong/insomnia-mockbin/.github/workflows/release.yaml'

A complete example, leveraging optional annotations for increased trust. For the complete example, you need the same details as the minimal example, as well as any of the optional annotations you wish to verify:

cosign verify \
  ghcr.io/kong/insomnia-mockbin:<tag>@sha256:<digest> \
  --certificate-oidc-issuer='https://token.actions.githubusercontent.com' \
  --certificate-identity-regexp='https://github.com/Kong/insomnia-mockbin/.github/workflows/release.yaml' \
  -a repo='Kong/insomnia-mockbin' \
  -a workflow='Package & Release'

Verify a container image provenance

Kong Insomnia Mockbin produces build provenance for docker container images for Github tags, which can be verified using cosign / slsa-verifier with attestations published to a Github Container registry with insomnia-mockbin repository.

Steps to verify provenance for signed Kong Insomnia Mockbin Docker container images:

  1. Fetch the image <manifest_digest> using regctl:

    regctl image digest ghcr.io/kong/insomnia-mockbin:<tag>
    
  2. A minimal example, used to verify an image without leveraging any annotations. For the minimal example, you only need Docker Image manifest, a GitHub repo name.

    cosign verify-attestation \
      ghcr.io/kong/insomnia-mockbin:<tag>@sha256:<manifest_digest> \
      --type='slsaprovenance' \
      --certificate-oidc-issuer='https://token.actions.githubusercontent.com' \
      --certificate-identity-regexp='^https://github.com/slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@refs/tags/v[0-9]+.[0-9]+.[0-9]+$'
    
    slsa-verifier verify-image \
      ghcr.io/kong/insomnia-mockbin:<tag>@sha256:<manifest_digest> \
      --print-provenance \
      --source-uri 'github.com/Kong/insomnia-mockbin'
    
  3. A complete example, leveraging optional annotations for increased trust. For the complete example, you need the same details as the minimal example, as well as any of the optional annotations you wish to verify:

    cosign verify-attestation \
      ghcr.io/kong/insomnia-mockbin:<tag>@sha256:<manifest_digest> \
      --type='slsaprovenance' \
      --certificate-oidc-issuer='https://token.actions.githubusercontent.com' \
      --certificate-identity-regexp='^https://github.com/slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@refs/tags/v[0-9]+.[0-9]+.[0-9]+$' \
      --certificate-github-workflow-repository='Kong/insomnia-mockbin' \
      --certificate-github-workflow-name='Package & Release'
    
    slsa-verifier verify-image \
      ghcr.io/kong/insomnia-mockbin:<tag>@sha256:<manifest_digest> \
      --print-provenance \
      --source-uri 'github.com/Kong/insomnia-mockbin' \
      --source-tag '<tag>'
    

Bugs and feature requests

Have a bug or a feature request? Please first read the issue guidelines and search for existing and closed issues. If your problem or idea is not addressed yet, please open a new issue.

Contributing

Please read through our contributing guidelines. Included are directions for opening issues, coding standards, and notes on development.

More over, if your pull request contains JavaScript patches or features, you must include relevant unit tests.

Editor preferences are available in the editor config for easy use in common text editors. Read more and download plugins at http://editorconfig.org.

License

Enterprise © Kong