Skip to content

superagentvsbuzz

MIT 176 16 16,564
38.7 million (month) Aug 22 2011 9.0.2(2 months ago)
1,919 2 11 MIT
Nov 11 2011 5.6 thousand (month) 1.2.1(2 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.

Buzz is a lightweight PHP library for issuing HTTP requests. It is built on top of the PHP curl extension and is designed to be easy to use and flexible.

While buzz isn't as feature rich as other clients it still supports http2 and is relatively easy to use.

Highlights


declarativeproxypopular
http2uses-curl

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')
use Buzz\Client\Curl;
use Buzz\Message\Request;
use Buzz\Message\Response;

$client = new Curl();
// GET request
$request = new Request('GET', 'http://httpbin.org/get');
$response = new Response();
$client->send($request, $response);
echo $response->getContent();

//POST request
$request = new Request('POST', '/api/resource', 'http://example.com');
$request->setContent(json_encode(['name' => 'John Doe']));
// we can also add headers or cookies:
$request->addHeader('Content-Type: application/json');
$request->addHeader('Cookie: name=foobar');
$response = new Response();
$client->send($request, $response);
echo $response->getContent();

// Buzz also supports http2 (see the 2.0 parameter)
$response = $client->sendRequest(
  new Request('GET', 'https://http2.golang.org/serverpush', [], null, '2.0')
);

Alternatives / Similar


Was this page helpful?