Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-call

Package Overview
Dependencies
Maintainers
4
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-call

make http requests

  • 5.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
901K
increased by6.97%
Maintainers
4
Weekly downloads
 
Created

What is http-call?

The http-call npm package is a lightweight HTTP client for making HTTP requests in Node.js. It provides a simple and intuitive API for performing various types of HTTP requests, handling responses, and managing errors.

What are http-call's main functionalities?

Making GET Requests

This feature allows you to make GET requests to a specified URL and handle the response. The example demonstrates how to fetch data from an API and log the response body.

const { get } = require('http-call');

async function fetchData() {
  try {
    const response = await get('https://api.example.com/data');
    console.log(response.body);
  } catch (error) {
    console.error('Error fetching data:', error);
  }
}

fetchData();

Making POST Requests

This feature allows you to make POST requests with a request body. The example demonstrates how to send data to an API and log the response body.

const { post } = require('http-call');

async function sendData() {
  try {
    const response = await post('https://api.example.com/data', { body: { key: 'value' } });
    console.log(response.body);
  } catch (error) {
    console.error('Error sending data:', error);
  }
}

sendData();

Handling Errors

This feature allows you to handle errors that occur during HTTP requests. The example demonstrates how to handle a 404 error specifically and log an appropriate message.

const { get } = require('http-call');

async function fetchData() {
  try {
    const response = await get('https://api.example.com/data');
    console.log(response.body);
  } catch (error) {
    if (error.statusCode === 404) {
      console.error('Resource not found');
    } else {
      console.error('Error fetching data:', error);
    }
  }
}

fetchData();

Other packages similar to http-call

Keywords

FAQs

Package last updated on 05 Dec 2019

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