Socket
Socket
Sign inDemoInstall

wreck

Package Overview
Dependencies
2
Maintainers
4
Versions
50
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    wreck

HTTP Client Utilities


Version published
Maintainers
4
Created

Package description

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

Readme

Source

wreck

HTTP Client Utilities

Build Status

License

This version of the package requires a commercial license. You may not use, copy, or distribute it without first acquiring a commercial license from Sideway Inc. Using this software without a license is a violation of US and international law. To obtain a license, please contact sales@sideway.com. The open source version of this package can be found here.

Keywords

FAQs

Last updated on 01 Jan 2024

Did you know?

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc