mye_aq
Last Updated: February 25, 2016
·
3.185K
· nategood
D2ce351ee414282b93dfdb672ce51430

Make cURL in PHP less sucky

https://github.com/nategood/httpful

Httpful is a simple, chainable, readable PHP library intended to make speaking HTTP sane. It let's the developer focus on interacting with APIs instead of sifting through curl set_opt pages and is an ideal PHP REST client.

Snippet:

$url = "http://search.twitter.com/search.json?q=" . urlencode('#PHP');

$response = Request::get($url)
    ->withXTrivialHeader('Just as a demo')
    ->send();

foreach ($response->body->results as $tweet) {
    echo "@{$tweet->from_user} tweets \"{$tweet->text}\"\n";
}
Say Thanks
Respond

1 Response
Add your response

1348
Dbcdc33cdabd0743668b302fe7bf6b2d

See also: Buzz Browser

use Buzz\Browser;

$url = "http://www.example.com";

$response = (new Browser())->post(
    $url, 
    array("x-trivial" => "Just as a demo"),
    "some body content to be POSTed here"
);
if (!$response->isSuccessful()) {
    echo "Error " . $response->getStatusCode() . ": " ;
    echo $response->getReasonPhrase();
} else {
    echo $response;
}

for a lower level approach to the above.

over 1 year ago ·