Skip to content

wreckvssymfony-http

BSD-3-Clause 3 7 383
226.6 thousand (month) Aug 06 2011 18.1.0(6 months ago)
1,898 8 - MIT
Apr 28 2019 186.5 thousand (month) v7.1.2(17 days ago)

Wreck is an HTTP client library for Node.js. It provides a simple, consistent API for making HTTP requests, including support for both the client and server side of an HTTP transaction.

Wreck is a very minimal but stable as it's part of Hapi web framework project. For web scraping, it doesn't offer required features like proxy configuration or http2 support so it's not recommended.

Symfony-http is a PHP library that provides a set of classes for working with HTTP requests and responses. It is part of the Symfony CMS framework, but can also be used independently.

Example Use


const Wreck = require('wreck');

// get request
Wreck.get('http://example.com', (err, res, payload) => {
    if (err) {
        throw err;
    }
    console.log(payload.toString());
});

// post request
const options = {
    headers: { 'content-type': 'application/json' },
    payload: JSON.stringify({ name: 'John Doe' })
};

Wreck.post('http://example.com', options, (err, res, payload) => {
    if (err) {
        throw err;
    }
    console.log(payload.toString());
});
<?php
use Symfony\Component\HttpClient\HttpClient;

// create a client object: 
$client = HttpClient::create();
// sent GET request
$response = $client->request('GET', 'https://httpbin.org/get');


// or POST request
$response = $client->request('POST', 'https://httpbin.org/post', [
    'headers' => [
        'Content-Type' => 'application/json',
    ],
    'json' => [
        'name' => 'John Doe',
        'email' => 'john.doe@example.com',
    ],
]);

// print response data:
$statusCode = $response->getStatusCode();
$content = $response->getContent();
echo "Status Code: $statusCode\n";
echo "Content: $content\n";

Alternatives / Similar


Was this page helpful?