Unirest HTTP Client for Node.js

0.6.0 · abandoned · verified Wed Apr 22

Unirest for Node.js is a lightweight HTTP client library designed to simplify common HTTP request patterns, including GET, POST, PUT, and file uploads. It offers features like automatic gzip decompression and response parsing, aiming to provide a concise, fluent API. The library's development has been dormant for approximately seven years, with its last stable version (0.11.0) published in 2017. Consequently, it lacks ongoing maintenance and a current release cadence. While it was once part of a multi-language HTTP library suite and associated with Kong, it is now largely superseded by more modern and actively maintained alternatives in the Node.js ecosystem, such as `axios` or `node-fetch`. Developers should be aware of its unmaintained status and potential compatibility issues with newer Node.js versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to make both POST and GET HTTP requests using Unirest 0.6.0's callback-based API. It includes basic error handling and logging of the response status and body.

const unirest = require('unirest');

// Example POST request using the callback-based API (typical for v0.6.0)
unirest.post('http://mockbin.com/request')
  .headers({'Accept': 'application/json', 'Content-Type': 'application/json'})
  .send({ "parameter": 23, "foo": "bar" })
  .end(function (response) {
    if (response.error) {
      console.error('Request failed:', response.error);
      // Log detailed error information for debugging
      if (response.error.body) console.error('Error Body:', response.error.body);
      if (response.error.status) console.error('Error Status:', response.error.status);
    } else {
      console.log('Request successful (callback style)!');
      console.log('Status:', response.status);
      console.log('Body:', response.body);
    }
  });

// Example GET request with direct callback argument (another common pattern in v0.6.0)
unirest.get('http://mockbin.com/status/200', function (response) {
  if (response.error) {
    console.error('GET Request failed:', response.error);
  } else {
    console.log('GET request successful (direct callback)!');
    console.log('Status:', response.status);
  }
});

view raw JSON →