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 🙏

© 2026 – Pkg Stats / Ryan Hefner

cypress-api-logger

v1.3.3

Published

Logs API Request and Response in Cypress Test Runner.

Readme

Cypress API Logger

CI npm version npm downloads License: MIT

cypress-api-logger is a Cypress plugin that logs detailed information about API requests and responses directly in the Cypress Test Runner. This tool helps you monitor and debug API interactions efficiently during your test execution.

Preview

What you'll see in the Cypress Test Runner:

LOGGER        --- LOGGING STARTED FOR GET : https://api.example.com/users
              | Status: 200
              | Request Headers: { "Content-Type": "application/json" }
              | Response Body:
              |   [{ "id": 1, "name": "Alice" }, ...]
              | Duration: 142ms

Features

  • Logs HTTP request details: method, URL, headers, body, etc.
  • Logs HTTP response details: status, headers, body, duration, etc.
  • Easy integration into existing Cypress projects.
  • Provides visibility into API interactions, helping to identify issues faster.
  • GraphQL support: auto-detects and logs queries, variables, and responses.
  • cy.intercept support: logs browser-level intercepted requests automatically.
  • Exclude URLs from logging via substring or wildcard patterns.
  • Include URLs (allowlist) — log only the services you care about.
  • Log only failures — reduce noise in CI by logging only status ≥ 400.
  • Mask sensitive fields — redact tokens, passwords, and API keys from logs.
  • Slow request detection — flag requests that exceed a configurable threshold.
  • onLog callback — pipe log data to Slack, Datadog, or any external reporter.

Installation

To install the cypress-api-logger plugin, run the following npm command:

npm install cypress-api-logger

Usage

  1. After installation, import the logger into your e2e.js (or support/index.js) file. import 'cypress-api-logger';
  2. The plugin will automatically log API request and response details in the Cypress Test Runner.

Example

After importing the plugin, simply use cy.request() in your tests. The plugin will log the relevant details automatically.

Sample Test:

describe('API Request Logging', () => {
  it('should log the request and response details', () => {
    cy.request('GET', 'https://jsonplaceholder.typicode.com/posts')
      .then((response) => {
        expect(response.status).to.eq(200);
      });
  });
});

Output in Cypress Test Runner:

  • Request Method: GET
  • Request URL: https://jsonplaceholder.typicode.com/posts
  • Response Status: 200
  • Response Body: <Response body content>
  • Duration: 123ms

Configuration

Currently, the plugin logs all API requests and responses by default. Custom configurations, such as filtering or modifying the log details, can be added in future versions.

  1. Global Configuration:
    You can set global configurations for the plugin using Cypress.env('apiLoggerConfig', {...}). These configurations will apply across all requests in the project.

    Default Configuration:

    • maxBodyLines: 50
      Controls the maximum number of lines displayed for the response body.

    • displayFields:
      ['method', 'url', 'status', 'requestBody', 'requestHeaders', 'responseBody', 'responseHeaders', 'duration', 'graphqlQuery']
      Specifies which fields should be displayed in the logs.

    • enableApiLogging: true
      Toggles API logging. When set to false, no logs will be displayed.

    • enableGraphQLLogging: true
      Toggles GraphQL API logging. When set to false, no logs will be displayed.

      Example Usage:

      To customize the configuration, add the following to your Cypress test or environment file:

      Cypress.env('apiLoggerConfig', {
        maxBodyLines: 100,
        displayFields: ['method', 'url', 'status'],
        enableApiLogging: false,
        enableGraphQLLogging: true,
      });
    • excludeUrls: []
      Array of URL patterns to skip logging. Supports exact substrings and * wildcards. Useful for ignoring health checks, analytics, or CDN requests.

      Cypress.env('apiLoggerConfig', {
        excludeUrls: ['/health', '/analytics', '*.cdn.com*'],
      });
    • logOnlyFailures: false
      When true, only requests with a response status >= 400 are logged. Ideal for CI pipelines where you only care about what broke.

      Cypress.env('apiLoggerConfig', {
        logOnlyFailures: true,
      });
    • maskFields: []
      Array of header and body field names to redact. Matching is case-insensitive. Matched values are replaced with ***MASKED*** in the log output — keeps tokens and passwords out of your test logs.

      Cypress.env('apiLoggerConfig', {
        maskFields: ['authorization', 'x-api-key', 'password'],
      });
    • includeUrls: []
      URL allowlist — the opposite of excludeUrls. When set, only requests matching at least one pattern are logged. Everything else is silently skipped. Supports substrings and * wildcards.

      Cypress.env('apiLoggerConfig', {
        includeUrls: ['/api/payments', '/api/orders'],
      });
    • slowThreshold: null
      Duration threshold in milliseconds. Requests that exceed it are flagged with a ⚠ SLOW indicator in the Cypress log display name and log message. Set to null (default) to disable.

      Cypress.env('apiLoggerConfig', {
        slowThreshold: 1000,  // flag requests slower than 1 second
      });
    • onLog: null
      Custom callback fired after every logged request. Receives the full (masked) log data object. Use it to pipe logs to Slack, Datadog, a file, or any external reporter.

      Cypress.env('apiLoggerConfig', {
        onLog: (data) => {
          // data: { method, url, status, duration, requestBody,
          //         requestHeaders, responseBody, responseHeaders,
          //         isGraphQL, isSlow }
          if (data.status >= 400) {
            cy.task('sendSlackAlert', data);
          }
        },
      });
  2. Per-Request Configuration: Users can also customize the logging behavior on a per-request basis by passing a config object inside the cy.request() options.

cy.intercept Support

cypress-api-logger also automatically logs requests intercepted with cy.intercept() when you provide a route handler function.

cy.intercept('GET', '/api/users', (req) => {
  req.continue((res) => {
    // your assertions here
    expect(res.statusCode).to.eq(200);
  });
}).as('getUsers');

The logger will output the same structured log (method, URL, status, headers, body, duration) for intercepted requests — no extra setup required.

Note: Logging only activates when a handler function is provided. Static stubs (cy.intercept('/api', { body: {} })) are passed through unchanged.

Contributing

Feel free to contribute to this project! Fork the repository, create a new branch, and submit a pull request with your improvements.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature-name)
  3. Commit your changes (git commit -m 'Add new feature')
  4. Push to the branch (git push origin feature-name)
  5. Create a new pull request

Bugs or Issues?

If you encounter any bugs or have suggestions, please open an issue in the GitHub repository.

About

Author: Hari Prasath VS

GitHub Repository: https://github.com/hariprasathvs/cypress-api-logger

License

This project is licensed under the MIT License .