Socket
Socket
Sign inDemoInstall

request-promise-core

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

request-promise-core

Core Promise support implementation for the simplified HTTP request client 'request'.


Version published
Maintainers
1
Created

What is request-promise-core?

The request-promise-core package is a foundational library for making HTTP requests in Node.js. It is designed to be a lightweight and flexible core for building HTTP request libraries with promise support. It provides the essential functionality for making HTTP requests and handling responses, and it can be extended or used as a base for more complex request libraries.

What are request-promise-core's main functionalities?

Basic HTTP Request

This feature allows you to make a basic HTTP GET request to a specified URI and handle the response using promises. The example demonstrates how to fetch a post from a placeholder API and log the response.

const request = require('request-promise-core');
const options = {
  method: 'GET',
  uri: 'https://jsonplaceholder.typicode.com/posts/1',
  json: true
};
request(options)
  .then(response => {
    console.log(response);
  })
  .catch(err => {
    console.error(err);
  });

Custom Request Options

This feature allows you to customize the HTTP request by specifying various options such as method, URI, and request body. The example demonstrates how to make a POST request to create a new post on a placeholder API.

const request = require('request-promise-core');
const options = {
  method: 'POST',
  uri: 'https://jsonplaceholder.typicode.com/posts',
  body: {
    title: 'foo',
    body: 'bar',
    userId: 1
  },
  json: true
};
request(options)
  .then(response => {
    console.log(response);
  })
  .catch(err => {
    console.error(err);
  });

Handling Errors

This feature demonstrates how to handle errors that occur during an HTTP request. The example shows how to catch and log errors when making a request to an invalid endpoint.

const request = require('request-promise-core');
const options = {
  method: 'GET',
  uri: 'https://jsonplaceholder.typicode.com/invalid-endpoint',
  json: true
};
request(options)
  .then(response => {
    console.log(response);
  })
  .catch(err => {
    console.error('Request failed:', err.message);
  });

Other packages similar to request-promise-core

Keywords

FAQs

Package last updated on 22 Jul 2020

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