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

request-compose

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

request-compose

Composable HTTP Client

  • 0.0.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
187K
decreased by-2.62%
Maintainers
1
Weekly downloads
 
Created

What is request-compose?

The request-compose npm package is a versatile tool for making HTTP requests and composing them in a functional manner. It allows for chaining requests, handling responses, and managing errors in a streamlined way.

What are request-compose's main functionalities?

Making HTTP Requests

This feature allows you to make HTTP requests using a simple and intuitive API. The example demonstrates how to make a GET request to an API endpoint and log the response body.

const { compose } = require('request-compose');
const { Request } = compose;

(async () => {
  const { res, body } = await Request({
    url: 'https://jsonplaceholder.typicode.com/posts/1',
    method: 'GET'
  });
  console.log(body);
})();

Chaining Requests

This feature allows you to chain multiple HTTP requests together. The example demonstrates making a GET request followed by a POST request, showing how to handle multiple requests in sequence.

const { compose } = require('request-compose');
const { Request } = compose;

(async () => {
  const { res: res1, body: body1 } = await Request({
    url: 'https://jsonplaceholder.typicode.com/posts/1',
    method: 'GET'
  });
  const { res: res2, body: body2 } = await Request({
    url: 'https://jsonplaceholder.typicode.com/posts',
    method: 'POST',
    body: { title: 'foo', body: 'bar', userId: 1 },
    json: true
  });
  console.log(body2);
})();

Error Handling

This feature provides robust error handling for HTTP requests. The example demonstrates how to catch and handle errors when a request fails.

const { compose } = require('request-compose');
const { Request } = compose;

(async () => {
  try {
    const { res, body } = await Request({
      url: 'https://jsonplaceholder.typicode.com/invalid-url',
      method: 'GET'
    });
    console.log(body);
  } catch (error) {
    console.error('Request failed:', error.message);
  }
})();

Other packages similar to request-compose

Keywords

FAQs

Package last updated on 21 Mar 2018

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