Insomnia logo
  • Documentation
  • Get Started for Free
    • Introduction to Insomnia
    • Install Insomnia
    • Send Your First Request
    • Import and Export Data
    • Environment Variables
    • Insomnia Accounts
    • Forgotten Passphrase
    • Organizations
    • Enable Enterprise membership
    • Configuring EE SSO
    • Integrating Insomnia Enterprise with Okta SAML 2.0
    • Integrating Insomnia Enterprise with Microsoft Azure/Entra ID SAML 2.0
    • Insomnia Whitelisting Guide for Enterprise Users
    • Insomnia Subscriptions
    • Insomnia Subscription Management
    • Scratch Pad Tutorial
    • Requests
    • Responses
    • Request Collections
    • Request Timeouts
    • Chaining Requests
    • Post CSV Data
    • SOAP Requests
    • gRPC
    • WebSocket Support
    • Get Started with Documents
    • Design Documents
    • Linting
    • GraphQL for OpenAPI
    • Migrate from Designer
    • Unit Testing
    • Stress Testing
    • Insomnia Storage Options Guide
    • Sync with Insomnia Cloud
    • Sync with Git
    • Key Security Features
    • Security Standards
    • Signup and Authentication
    • Analytics Collected
    • End to End Data Encryption
    • Authentication
    • Client Certificates
    • Generate Code Snippet
    • Cookie Management
    • Encoding
    • GraphQL Queries
    • Run in Insomnia Button
    • Key Maps
    • Proxy
    • Introduction to Plugins
    • Context Object Reference
    • Template Tags
    • Hooks and Actions
    • Custom Themes
    • FAQ
    • Application Data
    • SSL Validation
    • Password Recovery
    • Introduction to Inso CLI
    • Install Inso CLI
    • CLI Command Reference
      • inso generate config
      • inso run test
      • inso lint spec
      • inso export spec
      • inso script
      • OpenAPI Spec Reference
      • Using Custom Linting with Inso CLI
    • Configuration
    • Inso CLI on Docker
    • Continuous Integration
    • Kong Declarative Config (for decK)
    • Kong for Kubernetes
    • Insomnia Pre-request Script Overview
    • Insomnia API Mocking Overview

Insomnia API Mocking Overview

API mocks are useful for simulating an API endpoint. For example, when building a front end while the backend API is under construction and unstable, Insomnia allows us to customize responses from a set of API paths to simulate a static API. This mocked URL can then replace our front-end API backend URL.

Response Extractor

From the request collection screen, on the response pane to the right, we can use the Mock Response tab to extract the most recent response and API path from the currently selected request to build an API mock.

This feature is a time-saver when we already have our response structures within Insomnia that we would like to make available from our API mock.

Insomnia Cloud Mocks

Any logged-in user can create API mocks, accessible at mock.insomnia.rest. These mocks can be collaborated on with a team and accessed by anyone.

As a consumer of this mock server we can modify our environment (e.g. BACKEND_API_URL) to point at the Insomnia Cloud Mock server.

// Example .env file for your front-end application
BACKEND_API_URL=https://foobar.mock.insomnia.rest/
THIRD_PARTY_API_KEY=foo

Self-hosted Mocks

Enterprise plans have access to self-hosted mocks, providing increased control over usage.

Configuration details can be found at GitHub - Kong Insomnia Mockbin and a Docker image is available at ghcr.io/kong/insomnia-mockbin:master.

Instructions for running locally with Docker or NodeJS can be found on GitHub:

// Example .env file for your front-end application
BACKEND_API_URL=https://localhost:8080/bin/foobar
THIRD_PARTY_API_KEY=foo

Self-hosted Mocks (Example with Kubernetes)

Prerequisites

  1. Kubernetes Cluster: Ensure you have a Kubernetes cluster running.
  2. kubectl: You need the kubectl command-line tool configured to interact with your cluster.
  3. Helm: This is optional but useful if you’re using Helm charts for deployments.

Steps

  1. Create and modify the Deployment File: Create/Open deployment.yaml and make sure to replace any placeholder values with actual data. You might need to set values for the number of replicas, resource limits, and Mockbin-specific environment variables.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: insomnia-mock
      namespace: mock
    spec:
      replicas: 1  # Set the number of replicas
      selector:
        matchLabels:
          app: insomnia-mock
      template:
        metadata:
          labels:
            app: insomnia-mock
        spec:
          containers:
          - name: insomnia-mock
            image: ghcr.io/kong/insomnia-mockbin:master
            ports:
            - containerPort: 9080
            env:
              - name: MOCKBIN_PORT
                value: "9080"
              # Set other environment variables as required
    
  2. Deploy Mockbin: Run the following command to create the deployment in Kubernetes:

    kubectl apply -f deployment.yaml
    
  3. Configure the Service: Create/Open service.yaml. This file configures the service to expose Mockbin internally in the cluster.

    apiVersion: v1
    kind: Service
    metadata:
      name: insomnia-mock
      namespace: mock
    spec:
      type: ClusterIP
      ports:
      - name: mock
        port: 9080
        targetPort: 9080
      selector:
        app: insomnia-mock
    
  4. Deploy the Service: Run the following command:

    kubectl apply -f service.yaml
    
  5. Configure the Ingress: Create/Edit ingress.yaml to manage external access. This configuration will depend heavily on your specific domain and TLS requirements.

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: insomnia-mock-ingress
      namespace: mock
    spec:
      ingressClassName: nginx
      rules:
      - host: mock.your-domain.com
        http:
          paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: insomnia-mock
                port:
                  number: 9080
      tls:
      - hosts:
        - mock.your-domain.com
        secretName: insomnia-mock-tls
    
  6. Deploy the Ingress: Replace mock.your-domain.com with your actual domain and update the TLS secret names accordingly. Then, apply the configuration:

    kubectl apply -f ingress.yaml
    
  7. Check the Deployment Status:

    kubectl get deployments -n mock
    
  8. Check the Service:

    kubectl get services -n mock
    
  9. Check the Ingress:

    kubectl get ingress -n mock
    
  10. Edit your your front-end application .env to point to the Ingress host:

    // Example .env file for your front-end application
    BACKEND_API_URL=https://mock.your-domain.com/bin/foobar
    THIRD_PARTY_API_KEY=foo
    
Edit this page
Report an issue
    COMPANY
  • Insomnia
  • Blog
  • Changelog
  • Pricing
  • Careers
    PRODUCTS
  • Insomnia
  • Inso (CLI)
    RESOURCES
  • Sign In
  • Documentation
  • Support
    LEGAL
  • Privacy Policy
  • Terms & Conditions
© Kong Inc. 2021