🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@hapi/wreck

Package Overview
Dependencies
Maintainers
7
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@hapi/wreck

HTTP Client Utilities

18.1.0
unpublished
latest
Source
npm
Version published
Weekly downloads
1.2M
5.53%
Maintainers
7
Weekly downloads
 
Created

What is @hapi/wreck?

@hapi/wreck 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 and consistent API for making HTTP requests, handling redirects, and managing cookies.

What are @hapi/wreck's main functionalities?

Making HTTP GET Requests

This feature allows you to make HTTP GET requests to a specified URL and handle the response. The example fetches data from a placeholder API and logs the response.

const Wreck = require('@hapi/wreck');

async function fetchData() {
  const { res, payload } = await Wreck.get('https://jsonplaceholder.typicode.com/posts/1');
  console.log(JSON.parse(payload.toString()));
}

fetchData();

Making HTTP POST Requests

This feature allows you to make HTTP POST requests with a payload. The example sends a JSON object to a placeholder API and logs the response.

const Wreck = require('@hapi/wreck');

async function postData() {
  const payload = JSON.stringify({ title: 'foo', body: 'bar', userId: 1 });
  const { res, payload: responsePayload } = await Wreck.post('https://jsonplaceholder.typicode.com/posts', { payload });
  console.log(JSON.parse(responsePayload.toString()));
}

postData();

Handling Redirects

This feature allows you to handle HTTP redirects automatically. The example makes a GET request to a URL and follows up to 3 redirects.

const Wreck = require('@hapi/wreck');

async function fetchWithRedirect() {
  const { res, payload } = await Wreck.get('http://example.com', { redirects: 3 });
  console.log(payload.toString());
}

fetchWithRedirect();

Managing Cookies

This feature allows you to manage cookies for your HTTP requests. The example sets a cookie and makes a GET request with the cookie jar.

const Wreck = require('@hapi/wreck');

async function fetchWithCookies() {
  const jar = new Wreck.CookieJar();
  await jar.setCookie('session=abc123', 'http://example.com');
  const { res, payload } = await Wreck.get('http://example.com', { cookies: jar });
  console.log(payload.toString());
}

fetchWithCookies();

Other packages similar to @hapi/wreck

Keywords

utilities

FAQs

Package last updated on 10 Apr 2024

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