Using the iCyte API with PHP 5

We suggest you download the http_request2 PEAR package. Install it using you PEAR distribution. Require it into your script with:

require_once 'HTTP/Request2.php';

Construct the URL of the resource that you want to connect to (we suggest you use the json datatype), and instanciate a new HTTP_Request2 object:

$url = 'http://www.icyte.com/api/cytes.json';
$request = new HTTP_Request2($url);

Use the setAuth method to set authentication parameters for your request:

$request->setAuth('user@example.com', 'password');

Make the request with the send method, and check the result status with the getStatus method.

$request->send();
print 'STATUS: ' . $response->getStatus;

If the status is 200 (OK) then use the json_decode php method to construct an object out of the result data:

$cytes = json_decode($response->getBody());

This will result in a list objects that can be used as normal:

foreach ($cytes as $cyte) {
    print $cyte->title;
}

Entire cyte list script:

require_once 'HTTP/Request2.php';

$url = 'http://www.icyte.com/api/cytes.json';
$request = new HTTP_Request2($url);
$request->setAuth('user@example.com', 'password');

$request->send();
print 'STATUS: ' . $response->getStatus;

$cytes = json_decode($response->getBody());

foreach ($cytes as $cyte) {
    print $cyte->title;
}