needlevsbuzz
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.
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
http2uses-curl
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)
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')
);