Blog

2008 08 posts (3)

Ordering: Ascending Descending

1. Resource tree

2008-08-20 14:23:19 by Martynas Jusevičius

We recently internally redesigned our framework framework. Now the resource objects form a parent/child tree, where each resource is a node and contains its URI relative to the parent (instead of full URI relative to the host, as previously). The hierarchy was implemented using nested set support in Propel, which is way more efficient than the ID/parentID method that requires recursion and lots of database queries. The tree of our page would be:

This means that now resources can be treated as files and folder in a filesystem — copied/moved from one URI to another, renamed, given permissions etc. A sitemap of the site can be generated automatically. Of course, as before, they can be related to domain model objects which they stand for.

Add a comment Comments (4)

2. REST authentication?

2008-08-16 16:17:04 by Martynas Jusevičius

While developing a RESTful webservice, I realised I need some kind of authentication to only allow clients to execute certain HTTP methods on certain resources. For example, a client should only be able to able to GET/PUT its own placemarks at /placemarks/client1 but not others at /placemarks/client2.
In a regular Web application this would be solved in a simple way using sessions. But one of the REST principles is statelessness, which eliminates cookies and sessions. So this might be an old question, but what is the common authentication method between a client and a RESTful webservice? Is HTTP Basic/Digest enough here?

Add a comment Comments (8)

3. Creating KML with DOM

2008-08-09 12:04:14 by Martynas Jusevičius

We started working a little bit with location-based services. One of the tasks was to create a webservice endpoint to serve placemark information for a certain location. We chose Google's KML (Keyhole Markup Language) as the representation format. It has become an official Open Geospatial Consortium (OGC) standard.

This piece of code might be useful for those who have a similar need to serialize placemark objects in to KML. It is using PHP's Document Object Model (DOM) extension.

$doc = new DOMDocument("1.0", "UTF-8");
$kmlElem = $doc->createElementNS("http://earth.google.com/kml/2.2", "kml");
$doc->appendChild($kmlElem);
$documentElem = $doc->createElement("Document");
$kmlElem->appendChild($documentElem);

$places = PlacePeer::doSelect(new Criteria()); // retrieve placemark objects, e.g. from Propel model

foreach ($places as $place)
{
	$placemarkElem = $doc->createElement("Placemark");
	$documentElem->appendChild($placemarkElem);

	$nameElem = $doc->createElement("name");
	$placemarkElem->appendChild($nameElem);
	$nameElem->appendChild($doc->createTextNode($place->getName()));

	$descElem = $doc->createElement("description");
	$placemarkElem->appendChild($descElem);
	$descElem->appendChild($doc->createTextNode($place->getDescription()));

	$pointElem = $doc->createElement("Point");
	$coordElem = $doc->createElement("coordinates");
	
	$coordElem->appendChild($doc->createTextNode($place->getLng().",".$place->getLat().",0"));
	$pointElem->appendChild($coordElem);
	$placemarkElem->appendChild($pointElem);
}

$response->write($doc->saveXML()); // use the KML string, e.g. write it out to response

Add a comment Comments (40)

Ordering: Ascending Descending