New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-request-interceptor

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-request-interceptor

Low-level HTTP/HTTPS/XHR request interception library for NodeJS

  • 0.6.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
223K
increased by0.5%
Maintainers
1
Weekly downloads
 
Created

What is node-request-interceptor?

The node-request-interceptor package allows you to intercept and modify HTTP requests in Node.js. This can be useful for testing, mocking APIs, or modifying requests on the fly.

What are node-request-interceptor's main functionalities?

Intercepting HTTP Requests

This feature allows you to intercept HTTP requests made by the Node.js http module. You can log, modify, or mock these requests.

const { interceptClientRequest } = require('node-request-interceptor');

const interceptor = interceptClientRequest();

interceptor.use((req) => {
  console.log('Intercepted request:', req);
  return req;
});

// Example HTTP request
const http = require('http');
http.get('http://example.com', (res) => {
  res.on('data', (chunk) => {
    console.log('Response:', chunk.toString());
  });
});

Mocking HTTP Responses

This feature allows you to mock HTTP responses based on the request URL or other criteria. This is useful for testing purposes.

const { interceptClientRequest } = require('node-request-interceptor');

const interceptor = interceptClientRequest();

interceptor.use((req) => {
  if (req.url === 'http://example.com') {
    return {
      status: 200,
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ message: 'Mocked response' })
    };
  }
  return req;
});

// Example HTTP request
const http = require('http');
http.get('http://example.com', (res) => {
  res.on('data', (chunk) => {
    console.log('Response:', chunk.toString());
  });
});

Other packages similar to node-request-interceptor

Keywords

FAQs

Package last updated on 03 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc