Socket
Socket
Sign inDemoInstall

then-request

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

then-request

A request library that returns promises, inspired by request


Version published
Weekly downloads
914K
increased by3.25%
Maintainers
1
Weekly downloads
 
Created

What is then-request?

The then-request npm package is a simplified HTTP client for Node.js that uses promises. It allows you to make HTTP requests and handle responses in a straightforward manner using promises, making it easier to work with asynchronous code.

What are then-request's main functionalities?

Basic GET Request

This feature allows you to make a basic GET request to a specified URL. The response is handled using a promise, and the response body is logged to the console.

const request = require('then-request');

request('GET', 'https://jsonplaceholder.typicode.com/posts/1')
  .done(function (res) {
    console.log(res.getBody());
  });

POST Request with JSON Body

This feature allows you to make a POST request with a JSON body. The request sends data to the specified URL, and the response is handled using a promise.

const request = require('then-request');

request('POST', 'https://jsonplaceholder.typicode.com/posts', {
  json: {
    title: 'foo',
    body: 'bar',
    userId: 1
  }
}).done(function (res) {
  console.log(res.getBody());
});

Handling Response Headers

This feature allows you to access and log the response headers from an HTTP request. The headers are available in the response object.

const request = require('then-request');

request('GET', 'https://jsonplaceholder.typicode.com/posts/1')
  .done(function (res) {
    console.log(res.headers);
  });

Handling Errors

This feature demonstrates how to handle errors in HTTP requests. If the request fails, the error is caught and logged to the console.

const request = require('then-request');

request('GET', 'https://jsonplaceholder.typicode.com/invalid-url')
  .done(function (res) {
    console.log(res.getBody());
  }, function (err) {
    console.error('Request failed:', err);
  });

Other packages similar to then-request

FAQs

Package last updated on 05 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