Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
wreck
Advanced tools
Package description
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.
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');
Axios is a popular promise-based HTTP client for the browser and Node.js. It provides a simple and intuitive API for making HTTP requests and handling responses. Compared to Wreck, Axios has a larger community and more extensive documentation, making it a go-to choice for many developers.
Node-fetch is a lightweight module that brings the Fetch API to Node.js. It is designed to be a minimalistic and straightforward HTTP client. Compared to Wreck, node-fetch is more focused on providing a fetch-like experience in Node.js, making it a good choice for developers familiar with the Fetch API.
Request is a simplified HTTP client for Node.js, designed to be easy to use and flexible. It has been deprecated, but it remains widely used in many legacy projects. Compared to Wreck, Request offers a more extensive set of features and options, but its deprecation means it is no longer actively maintained.
Readme
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.
FAQs
HTTP Client Utilities
We found that wreck demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.