Skip to content

superagentvshttpclient

MIT 176 16 16,564
38.7 million (month) Aug 22 2011 9.0.2(2 months ago)
699 4 94 ruby
Jul 25 2009 3.8 million (month) 2.8.3(7 years ago)

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.

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)

Highlights


declarativeproxypopular

Example Use


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')
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?