Skip to content

needlevshttpclient

MIT 83 4 1,619
30.4 million (month) Dec 11 2011 3.3.1(7 months ago)
699 4 94 ruby
Jul 25 2009 3.8 million (month) 2.8.3(7 years 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.

HTTPClient is a Ruby gem that provides a simple and flexible interface for making HTTP requests. It's a full-featured HTTP client library with support for cookies, redirects, proxy, and more. It's built on top of the libwww-perl library, which is a widely-used, robust and well-documented library.

Features:

  • methods like GET/HEAD/POST/* via HTTP/1.1.
  • HTTPS(SSL), Cookies, proxy, authentication(Digest, NTLM, Basic), etc.
  • asynchronous HTTP request, streaming HTTP request.
  • debug mode CLI.
  • by contrast with net/http in standard distribution;
  • Cookies support
  • MT-safe
  • streaming POST (POST with File/IO)
  • Digest auth
  • Negotiate/NTLM auth for WWW-Authenticate (requires net/ntlm module; rubyntlm gem)
  • NTLM auth for Proxy-Authenticate (requires 'win32/sspi' module; rubysspi gem)
  • extensible with filter interface
  • you don't have to care HTTP/1.1 persistent connection (httpclient cares instead of you)

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)
require 'httpclient'

client = HTTPClient.new
# GET requests
response = client.get("http://httpbin.org/get")
puts response.content

# POST requests
data = { name: "value" }
response = client.post("http://httpbin.org/post", data)
puts response.content

Alternatives / Similar


Was this page helpful?