Hoppscotch

repository·main·Indexed 13 days ago

https://github.com/hoppscotch/hoppscotch

An open-source API development ecosystem for testing REST, GraphQL, WebSocket, and other API protocols. Includes a web application, a cross-platform Agent for CORS bypass and mTLS, and a CLI for running collection tests in CI environments.

Tokens
113.4K
Snippets
361
Records
534
Agent score
99%

What's inside Hoppscotch

  1. Overview of Hoppscotch JavaScript Sandbox

    main

    The hoppscotch-js-sandbox package provides a secure environment for executing security-sensitive external JavaScript scripts. It is designed to isolate and run code that would otherwise pose a risk to the main application environment.

    It currently powers the following Hoppscotch features:

    • Hoppscotch Test Scripts: Scripts used to validate API responses.
    • Hoppscotch Pre Request Scripts: Scripts used to modify requests before they are sent.
  2. Manage API requests with Environments and Variables

    main

    Environments allow you to store and reuse values across different requests and scripts, making it easier to switch between development, staging, and production settings.

    Key Features

    • Unlimited environments and variables: Create as many as needed.
    • Initialization: Variables can be initialized through Pre-Request Scripts.
    • Portability: Export and import environments via GitHub Gists.
    • Efficiency: By using variables, you only need to update a value in one place to reflect changes throughout your entire request suite.
  3. How the Hoppscotch Kernel architecture works

    main

    The Hoppscotch Kernel is designed as a minimal abstraction layer that mediates between high-level application logic and low-level platform implementations.

    It is structured into three primary modules:

    1. IO Module: Handles file systems and external resources.
    2. Relay Module: Manages optimized network operations.
    3. Store Module: Provides persistent storage with encryption support.

    Developers should favor composition over modifying the kernel directly, as the codebase is intentionally minimal to provide only the necessary building blocks for features.

  4. Automate requests with Pre-Request and Post-Request Scripts

    main

    Hoppscotch allows you to execute JavaScript code at different stages of the request lifecycle to automate setup and validation.

    Pre-Request Scripts

    Executed before the request is sent. Use these to:

    • Set environment variables.
    • Include dynamic timestamps in request headers.
    • Inject random alphanumeric strings into URL parameters.
    • Run any arbitrary JavaScript function.

    Post-Request Tests

    Executed after the response is received. Use these to:

    • Check the status code as an integer.
    • Filter response headers.
    • Parse response data.
    • Set environment variables based on the response.
    • Run custom JavaScript validation logic.
  5. Understand Capabilities Configuration in Hoppscotch Desktop

    main

    The Hoppscotch Desktop app uses a capabilities configuration (typically in default.json) to define permissions for windows, webviews, and remote URLs. This configuration is essential for supporting multi-tenancy and dynamic organization contexts.

    Key Configuration Fields

    • windows: An array of window labels allowed to perform certain actions.
    • webviews: An array of webview labels allowed to perform certain actions.
    • remote.urls: An array of URL patterns allowed for remote access.

    Multi-tenancy and Wildcards

    Because the desktop app supports dynamic organization hostnames (e.g., app://acme_hoppscotch_io/), the configuration uses wildcards (*) to ensure that new webviews created for different organizations are automatically granted the necessary permissions without requiring a rebuild of the application.

    Security Model

    Even when using wildcards, the application maintains security through several layers:

    1. app:// Protocol Sandboxing: The app:// protocol is managed by the tauri-plugin-appload plugin. Only content from the local bundle cache is accessible via this protocol, preventing external websites from injecting content into this namespace.
    2. Origin Isolation: Each app:// origin is isolated. A webview at app://org1_hoppscotch_io/ cannot access content from app://org2_hoppscotch_io/.
    3. IPC Command Validation: While wildcards allow IPC (Inter-Process Communication) calls from any app:// origin, the Tauri commands themselves perform strict authorization checks on the inputs.
    {
      "windows": ["*"],
      "webviews": ["*"],
      "remote": {
        "urls": ["app://*"]
      }
    }
  6. Configure Domain-Specific Settings

    main

    The agent supports per-domain configuration overrides. You can set global defaults using the * domain or define specific settings for individual domains (e.g., api.example.com).

    Domain Management

    • Global Defaults: Settings applied to all domains (domain: *).
    • Domain Overrides: Specific settings for individual domains.
    • Domain Addition/Removal: Use the domain management modal to add new domains or remove custom ones (the global default cannot be removed).

    SSL/TLS Security Settings

    For each domain, you can configure:

    • Verify Host: Enable/disable hostname verification.
    • Verify Peer: Enable/disable peer certificate verification.
    • CA Certificates: Upload custom Certificate Authority certificates for domain validation.
    • Client Certificates: Configure certificates for mutual TLS (mTLS).
  7. Ensure Signing Key Persistence

    main

    The server requires a stable signing key to prevent "Invalid signature" errors when users have cached bundles from previous instances.

    Key Resolution Order

    1. Environment variables: WEBAPP_SERVER_SIGNING_KEY, WEBAPP_SERVER_SIGNING_SEED, or WEBAPP_SERVER_SIGNING_SECRET.
    2. Key file on disk at the path specified by WEBAPP_SERVER_SIGNING_KEY_FILE (default: /data/webapp-server/signing.key).
    3. Auto-generate and persist to disk.
    4. Ephemeral fallback (logs the key for manual configuration).

    Deployment Strategies

    • Kubernetes/Multi-replica: To ensure all replicas use the same key, either mount a persistent volume at /data/webapp-server or set the WEBAPP_SERVER_SIGNING_SECRET to the same value across all replicas.
    • Single Instance: Ensure the server has write permissions to /data/webapp-server so it can persist the auto-generated key.
  8. Configure environment variables and iteration data

    main

    Environment Files

    When using the -e or --env flag, provide a JSON file where keys represent variable names:

    {
      "ENV1": "value1",
      "ENV2": "value2"
    }

    In your Hoppscotch scripts, access these using: pw.env.get("ENV1").

    Iteration Data (CSV)

    When using --iteration-data <file_path>, provide a CSV file. For each row (iteration), the values are injected into the environment using the header names as keys:

    key1,key2,key3
    value1,value2,value3
    value4,value5,value6
    • Iteration 1: key1=value1, key2=value2, key3=value3
    • Iteration 2: key1=value4, key2=value5, key3=value6
  9. Organize requests with Collections and Workspaces

    main

    Hoppscotch provides hierarchical structures to manage large numbers of API requests.

    Collections

    Keep requests organized using collections and nested folders.

    • Supports unlimited collections, folders, and requests.
    • Export/Import: Save collections as files or GitHub Gists.
    • Sync: Collections are synced with your cloud or local session storage.

    Workspaces

    Use Workspaces to separate different projects or environments (e.g., Personal vs. Team).

    • Create unlimited workspaces.
    • Easily switch between workspaces to manage multiple projects without cluttering your view.
  10. Configure Proxy Routing

    main

    The agent supports HTTP/HTTPS proxy routing, including support for proxy authentication (e.g., NTLM).

    Configuration Steps

    1. Select the target domain in the Agent settings.
    2. Toggle the Proxy switch to enable it.
    3. Enter the Proxy URL (e.g., http://proxy.example.com:8080).
    4. If authentication is required, enter the Username and Password in the provided fields.