Skip to content

needlevshttp.rb

MIT 83 4 1,619
30.4 million (month) Dec 11 2011 3.3.1(7 months ago)
2,994 10 95 NA
Mar 20 2015 447 (month) 0.12.0(6 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.

http is an HTTP library for Ruby, it's a fork of the Ruby standard library Net::HTTP. It is designed to provide a more modern and consistent API for making HTTP requests and handling responses.

One of the main goals of http is to simplify the process of making HTTP requests and handling responses. It provides a consistent API for making requests and handling responses across different versions of Ruby and different HTTP libraries, making it easier to write cross-compatible code.

http supports all the standard HTTP methods such as GET, POST, PUT, DELETE, and PATCH, and allows you to set headers, query parameters, and request bodies.

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 'http'

# GET request
response = HTTP.get("http://httpbin.org/get")
puts response.body
puts response.status
puts response.headers

# POST request
response = HTTP.post("http://httpbin.org/post", json: { title: 'foo', body: 'bar', userId: 1 })
puts response.body

Alternatives / Similar


Was this page helpful?