Skip to content

needlevssuperagent

MIT 83 4 1,619
30.4 million (month) Dec 11 2011 3.3.1(7 months ago)
16,564 16 176 MIT
Aug 22 2011 38.7 million (month) 9.0.2(2 months ago)

needle is an HTTP client library for Node.js that provides a simple, flexible, and powerful API for making HTTP requests. It supports all major HTTP methods and has a clean and easy-to-use interface for handling responses and errors.

superagent is an HTTP client library for Node.js that provides a simple, flexible, and powerful API for making HTTP requests. It supports all major HTTP methods, and has a clean and easy-to-use interface for handling responses and errors.

what differentiates superagent from other http clients is its simple declarative API.

Highlights


declarativeproxypopular

Example Use


const needle = require('needle');

// needle supports both Promises and async/await
needle.get('https://httpbin.org/get', (err, res) => {
    if (err) {
        console.error(err);
        return;
    }
    console.log(res.body);
});

const response = await needle.get('https://httpbin.org/get')

// concurrent requests can be sent using Promise.all
const results = await Promise.all([
  needle.get('http://httpbin.org/html'),
  needle.get('http://httpbin.org/html'),
  needle.get('http://httpbin.org/html'),
])

// POST requests
const data = { name: 'John Doe' };
await needle.post('https://api.example.com', data)

// proxy
const options = {
    proxy: 'http://proxy.example.com:8080'
};
await needle.get('https://httpbin.org/ip', options)

// headers and cookies
const options = {
  headers: {
      'Cookie': 'myCookie=123',
      'X-My-Header': 'myValue'
  }
};
await needle.get('https://httpbin.org/headers', options)
const superagent = require('superagent');

// superagent supports both Promises and async/await
superagent.get('https://httpbin.org/get')
    .then(res => console.log(res.text))
    .catch(err => console.error(err));
const response = superagent.get('https://httpbin.org/get')

// post requests:
superagent.post('https://httpbin.org/post').send({ name: 'John Doe' })

// setting proxy
superagent.get('https://httpbin.org/ip').proxy('http://proxy.example.com:8080')

// settings headers and proxies
superagent.get('https://httpbin.org/headers').set('Cookie', 'myCookie=123').set('X-My-Header', 'myValue')

Alternatives / Similar


Was this page helpful?