Simple Asynchronous HTTP Client

2.0.5 · abandoned · verified Wed Apr 22

Reqwest is a browser-focused JavaScript library designed for making asynchronous HTTP requests, offering support for XMLHttpRequest, JSONP, CORS, and the CommonJS Promises/A specification. While it provided isomorphic capabilities allowing use in Node.js via the `xhr2` peer dependency, its primary intention and optimization were for client-side AJAX operations. The package is currently at version 2.0.5 and has not received any updates since August 2015. This effectively marks it as an abandoned project. Its Promise implementation adheres to an older specification (Promises/A), which may not be fully compatible with the ES2015+ Promises/A+ standard or modern `async/await` patterns. For contemporary JavaScript development, the native Fetch API or actively maintained alternatives like `axios` are generally preferred due to `reqwest`'s lack of ongoing support and potential compatibility issues with modern environments and security practices.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates `reqwest` usage for simple GET requests with callbacks, POST requests with JSON data and promises, and a placeholder for JSONP.

const reqwest = require('reqwest');

// Example 1: Basic GET request with callback
reqwest('https://jsonplaceholder.typicode.com/posts/1', function (resp) {
  console.log('GET with callback response:', resp);
});

// Example 2: POST request with JSON data and Promises
reqwest({
    url: 'https://jsonplaceholder.typicode.com/posts',
    method: 'post',
    type: 'json',
    contentType: 'application/json',
    data: JSON.stringify({ title: 'foo', body: 'bar', userId: 1 }),
    headers: {
        'X-Custom-Header': 'MyValue'
    }
})
.then(function (resp) {
  console.log('POST with Promise success:', resp);
})
.fail(function (err, msg) {
  console.error('POST with Promise error:', err, msg);
})
.always(function () {
  console.log('POST request completed (always).');
});

// Example 3: JSONP request (assuming a JSONP endpoint like 'https://example.com/data.jsonp?callback=?')
// For demonstration, this won't run without a live JSONP service.
reqwest({
    url: 'https://httpbin.org/jsonp?callback=?', // Using a placeholder for demonstration
    type: 'jsonp',
    jsonpCallback: 'callback',
    success: function (resp) {
        console.log('JSONP request successful:', resp);
    },
    error: function (err) {
        console.error('JSONP request failed:', err);
    }
});

view raw JSON →