I’m working on the next generation data access layer for Digg right now, which is basically a REST layer built on top of a partitioned and multihomed database setup. The general idea is that we’ll send GET
, POST
, PUT
and DELETE
requests to URI’s on our services layer to access and manipulate data. PHP makes accessing GET
and POST
easy via $_GET
and $_POST
. DELETE
isn’t an issue since what we’re deleting is just the entity defined by the URI (e.g. Sending DELETE
to /2.0/User/1234.xml
will delete User 1234).
After a few days work I can create, fetch and delete entities from this setup. Today I started working on implementing the PUT
method. I always knew PHP wasn’t exactly top notch when it came to PUT
support, but I had no idea how annoying it would be to find a simple solution for parsing PUT
information. After some digging around this is what I’ve figured out.
$put = array(); parse_str(file_get_contents('php://input'), $put);
That should parse everything into a native PHP array, including arguments like foo[bar]=1&foo[baz]=2
. If anyone knows of a more native way of doing this please let me know.