From http://coreymaynard.com/blog/creating-a-restful-api-with-php/