简体   繁体   中英

How to use Httpful PHP Library

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!

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM