Mostly PHP/mysql_foo() code this time around, as I set myself the modest task of implementing the GET and POST methods on the root of the triplespace application. These aren’t public yet, as the POST method actually creates a new database table to store the triples for the newly-created triplespace, and I think I need some sort of password protection in place (probably plain old HTTP digest authentication) before I release it onto a production server…
For the time being, all the data being passed back and forth is in plaintext. You POST a triplespace name as a bare string to triplespace/, and you get back a 201 status code and a location header pointing to the new triplespace. GET returns a list of URLs of triplespaces on the server, separated by newlines. Maybe XML would be better, because then we could use client-side XSLT to make pretty pages for browsers to display to human beings. Maybe also I should use the POST format used by HTML forms, so that those same browsers can be used to submit requests. We’ll see. This is really a web service for applications, so browser-based interaction isn’t a priority; but it might be friendly to enable it, all the same.
function get_post_lines() {
$ph = fopen("php://input", "rb");
$lines = array();
$i = 0;
while (!feof($ph)) {
$line = fgets($ph);
$lines[i] = $line;
$i++;
}
fclose($ph);
return $lines;
}
Spot the mistake? Jeez. Whose idea was it to parse unrecognised tokens in array indices as string literals…?
In the next installment, I hope to present some actual storage and retrieval of triples. I will also talk some more about how I’m using Python to test this stuff.