Skip to content

needlevsem-http-request

MIT 83 4 1,631
53.5 million (month) Dec 11 2011 3.5.0(2026-03-12 22:24:55 ago)
1,219 4 17 MIT
Oct 25 2009 298.2 thousand (month) 1.1.7(2020-08-31 21:38:00 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.

em-http-request is a Ruby gem for making asynchronous HTTP requests using EventMachine. It allows you to perform multiple requests simultaneously and handle the responses as they come in, rather than waiting for each request to complete before making the next one.

In short it supports: - Asynchronous HTTP API for single & parallel request execution - Keep-Alive and HTTP pipelining support - Auto-follow 3xx redirects with max depth - Automatic gzip & deflate decoding - Streaming response processing - Streaming file uploads - HTTP proxy and SOCKS5 support - Basic Auth & OAuth - Connection-level & global middleware support - HTTP parser via http_parser.rb - Works wherever EventMachine runs: Rubinius, JRuby, MRI

Example Use


```javascript 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) ```
```ruby EventMachine.run { http = EventMachine::HttpRequest.new('http://google.com/').get :query => {'keyname' => 'value'} # add callback for errors: http.errback { p 'Uh oh'; EM.stop } # add callback for successful requests http.callback { p http.response_header.status p http.response_header p http.response EventMachine.stop } } ```

Alternatives / Similar


Was this page helpful?