PUTting PHP to Restful APIs (Like CouchDB) as JSON
(If you just want to know how to PUT data to a Restful API, jump to The Solution)
Recently, I started trying to figure out how to use CouchDB. Since I wanted a large set of data that I understood, I decided to use the same data that we use at the office. Even though that data is stored in a MySQL database, it’s more easily accessed via a data abstraction layer in one of the PHP frameworks we use so I really needed to send PHP arrays to CouchDB. Since this would be a one way operation (the data is only for my purposes, there’s no need send it back to PHP) I decided it made more sense to use the raw CouchDB REST API via cURL than it did to figure out one of the PHP CouchDB libraries (and PECL wouldn’t install the “official” one – yet another reason I hate Centos).