Socket
Socket
Sign inDemoInstall

wreck

Package Overview
Dependencies
Maintainers
4
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wreck

HTTP Client Utilities


Version published
Weekly downloads
176K
increased by92.38%
Maintainers
4
Weekly downloads
 
Created

What is wreck?

The 'wreck' npm package is a powerful HTTP client library for Node.js, designed to make HTTP requests and handle responses with ease. It is part of the hapi ecosystem and provides a simple API for making HTTP requests, handling redirects, and managing cookies.

What are wreck's main functionalities?

Making HTTP GET Requests

This feature allows you to make HTTP GET requests to a specified URL. The code sample demonstrates how to use Wreck to fetch data from a URL and log the response status code and payload.

const Wreck = require('wreck');

async function fetchData(url) {
  try {
    const { res, payload } = await Wreck.get(url);
    console.log('Response:', res.statusCode);
    console.log('Payload:', payload.toString());
  } catch (err) {
    console.error('Error:', err);
  }
}

fetchData('https://jsonplaceholder.typicode.com/posts/1');

Making HTTP POST Requests

This feature allows you to make HTTP POST requests with a payload. The code sample demonstrates how to use Wreck to send data to a URL and log the response status code and payload.

const Wreck = require('wreck');

async function postData(url, data) {
  try {
    const { res, payload } = await Wreck.post(url, { payload: data });
    console.log('Response:', res.statusCode);
    console.log('Payload:', payload.toString());
  } catch (err) {
    console.error('Error:', err);
  }
}

postData('https://jsonplaceholder.typicode.com/posts', { title: 'foo', body: 'bar', userId: 1 });

Handling Redirects

This feature allows you to handle HTTP redirects automatically. The code sample demonstrates how to use Wreck to follow up to 3 redirects when making a GET request.

const Wreck = require('wreck');

async function fetchWithRedirect(url) {
  try {
    const { res, payload } = await Wreck.get(url, { redirects: 3 });
    console.log('Response:', res.statusCode);
    console.log('Payload:', payload.toString());
  } catch (err) {
    console.error('Error:', err);
  }
}

fetchWithRedirect('http://example.com');

Managing Cookies

This feature allows you to manage cookies for your HTTP requests. The code sample demonstrates how to use Wreck to set a cookie and include it in a GET request.

const Wreck = require('wreck');

async function fetchWithCookies(url) {
  const jar = Wreck.jar();
  jar.setCookie('session=abc123', url);

  try {
    const { res, payload } = await Wreck.get(url, { cookies: jar });
    console.log('Response:', res.statusCode);
    console.log('Payload:', payload.toString());
  } catch (err) {
    console.error('Error:', err);
  }
}

fetchWithCookies('http://example.com');

Other packages similar to wreck

Keywords

FAQs

Package last updated on 03 Nov 2018

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