I'm trying to connect to a RESTful web service, but I'm having some troubles, especially when sending data over PUT and DELETE. With cURL, PUT requires a file to send, and DELETE is just weird. I'm perfectly capable of writing a client using PHP's socket support and writing the HTTP headers myself, but I wanted to know whether you guys have ever used or seen a REST client for PHP?
So as it turns out, Zend_Rest_Client isn't a REST client at all — it does not support the PUT and DELETE methods for example. After trying to kludge it into working with an actual RESTful service I got fed up and wrote a proper REST client for PHP:
http://github.com/educoder/pest
It's still missing a few things but if it gets picked up I'll put some more work into it.
Here's a usage example with the OpenStreetMap REST service:
<?php /** * This PestXML usage example pulls data from the OpenStreetMap API. * (see http://wiki.openstreetmap.org/wiki/API_v0.6) **/ require_once 'PestXML.php'; $pest = new PestXML('http://api.openstreetmap.org/api/0.6'); // Retrieve map data for the University of Toronto campus $map = $pest->get('/map?bbox=-79.39997,43.65827,-79.39344,43.66903'); // Print all of the street names in the map $streets = $map->xpath('//way/tag[@k="name"]'); foreach ($streets as $s) { echo $s['v'] . "\n"; } ?>
Currently it uses curl but I may switch it to HTTP_Request or HTTP_Request2 down the line.
Update: Looks like quite a few people have jumped on this. Pest now has support for HTTP authentication and a bunch of other features thanks to contributors on GitHub.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With