2

I'm trying to learn REST, and thought it might be good to start with a PHP REST client such as Httpful. I just can't seem to get it to work. I downloaded the httpful.phar file and placed it in my working directory. Then created a simple php file with the following contents from an example on the their site:

<?php
// Point to where you downloaded the phar
include('httpful.phar');

$uri = "https://www.googleapis.com/freebase/v1/mqlread?query=%7B%22type%22:%22/music/artist%22%2C%22name%22:%22The%20Dead%20Weather%22%2C%22album%22:%5B%5D%7D";
$response = Request::get($uri)->send();

echo 'The Dead Weather has ' . count($response->body->result->album) . " albums.\n";
?>

I've tried multiple examples on the site, but only get a blank page when I load it in my browser.

Thanks for any help you can give!

Derek Morgan
  • 155
  • 1
  • 2
  • 15

1 Answers1

5

This library uses Namespaces. Either use a complete classname or use the class

With a complete Classname:

\Httpful\Request::get($uri)->send();

With a use:

use Httpful\Request;
Request::get($uri)->send();

The sample code sadly is very incomplete on the website, but you can get the hint from sample below topic "INSTALL OPTION 1: PHAR" or from the actual source code inside the phar.

http://phphttpclient.com/

ToBe
  • 2,589
  • 1
  • 14
  • 28
  • I tried both the complete Classname and a use, however, I get a new error now - Fatal error: Call to undefined function Httpful\curl_init() in phar:///var/www/phphttpclient/httpful.phar/Httpful/Request.php on line 776 – Derek Morgan May 28 '14 at 14:37
  • 1
    You need to install the curl extension for PHP. Httpful seems to need this. What OS are you using? – ToBe May 28 '14 at 14:55
  • 1
    Thanks everyone! Installed curl through linux terminal and it's now working. – Derek Morgan May 28 '14 at 14:57