Socket
Socket
Sign inDemoInstall

light-my-request

Package Overview
Dependencies
Maintainers
8
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

light-my-request

Fake HTTP injection library


Version published
Maintainers
8
Created

What is light-my-request?

The light-my-request npm package is a lightweight HTTP request simulation tool designed primarily for testing purposes. It allows developers to simulate HTTP requests to their Node.js applications without the need for a real server. This is particularly useful for testing route handlers and middleware in isolation.

What are light-my-request's main functionalities?

Simulate HTTP GET Request

This feature allows you to simulate an HTTP GET request to a given handler function. The response can then be inspected to verify the behavior of the handler.

const { inject } = require('light-my-request');
const handler = (req, res) => { res.end('Hello, world!'); };

inject(handler, { method: 'GET', url: '/' }, (err, res) => {
  console.log(res.payload); // 'Hello, world!'
});

Simulate HTTP POST Request with Payload

This feature allows you to simulate an HTTP POST request with a payload. The handler can process the payload, and the response can be inspected to verify the behavior.

const { inject } = require('light-my-request');
const handler = (req, res) => {
  let body = '';
  req.on('data', chunk => { body += chunk; });
  req.on('end', () => { res.end(`Received: ${body}`); });
};

inject(handler, { method: 'POST', url: '/', payload: 'Hello, world!' }, (err, res) => {
  console.log(res.payload); // 'Received: Hello, world!'
});

Simulate HTTP Request with Headers

This feature allows you to simulate an HTTP request with custom headers. The handler can access these headers, and the response can be inspected to verify the behavior.

const { inject } = require('light-my-request');
const handler = (req, res) => {
  res.end(`Header: ${req.headers['x-custom-header']}`);
};

inject(handler, { method: 'GET', url: '/', headers: { 'x-custom-header': 'test-value' } }, (err, res) => {
  console.log(res.payload); // 'Header: test-value'
});

Other packages similar to light-my-request

Keywords

FAQs

Package last updated on 12 Sep 2023

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