Index: Dev/branches/rest-dojo-ui/server/api.php
===================================================================
--- Dev/branches/rest-dojo-ui/server/api.php	(revision 275)
+++ Dev/branches/rest-dojo-ui/server/api.php	(revision 292)
@@ -74,5 +74,5 @@
             set_session_cookie($response, $user);
         } else {
-            throw new ResponseException("No email and password provided.",Response::BADREQUEST);
+            throw new ResponseException("No email and password provided.", Response::BADREQUEST);
         }
         $response->body = $user;
@@ -83,13 +83,19 @@
 
 /**
- * @uri /data/\w+
+ * @uri /data/\w+(/\w+)?
  */
-class DataCollectionResource extends Resource {
-
-    function getType($request) {
+class DataResource extends Resource {
+
+    function getTypeAndUid($request) {
         $uri = get_clean_uri($request);
         $path = explode('/', $uri);
-        $type = $path[2];
-        return $type;
+
+        $info = array();
+        $info['type'] = $path[2];
+        if (isset($path[3])) {
+            $info['uid'] = $path[3];
+        }
+        
+        return $info;
     }
 
@@ -98,8 +104,16 @@
         restore_session($response);
 
-        $type = $this->getType($request);
-        $objects = $type::get(array());
-
-        $response->body = $objects;
+        $info = $this->getTypeAndUid($request);
+        if (isset($info['uid'])) {
+            $objects = $info['type']::get(array('uid' => $info['uid']));
+            if (empty($objects)) {
+                throw new ResponseException("Object not found", Response::NOTFOUND);
+            }
+            $response->body = $objects[0];
+        } else {
+            $objects = $info['type']::get(array());
+            $response->body = $objects;
+        }
+
         return $response;
     }
@@ -107,13 +121,20 @@
     function post($request) {
         $response = new Response($request);
-        restore_session($response);
-
-        $type = $this->getType($request);
+        $user = restore_session($response);
+
+        $info = $this->getTypeAndUid($request);
         $onlyAdd = $request->ifNoneMatch('*');
         $onlyUpdate = $request->ifMatch('*');
 
-        $object = FALSE;
-        if (isset($request->data->uid)) {
-            $objects = $type::get(array('uid' => $request->data->uid));
+        $uid = null;
+        if (isset($info['uid'])) {
+            $uid = $info['uid'];
+        } else if (isset($request->data->uid)) {
+            $uid = $request->data->uid;
+        }
+
+        $object = null;
+        if ($uid) {
+            $objects = $info['type']::get(array('uid' => $uid));
             if (!empty($objects)) {
                 $object = $objects[0];
@@ -126,5 +147,5 @@
 
         if (!$object) {
-            $object = new $type(null);
+            $object = new $info['type']($uid);
             $response->code = Response::CREATED;
         } else {
@@ -134,71 +155,6 @@
             $object->$key = $val;
         }
-        if (!$object->save()) {
-            throw new ResponseException("Save failed", Response::INTERNALSERVERERROR);
-        }
-
-        $response->body = $object;
-        return $response;
-    }
-
-    function put($request) {
-        return $this->post($request);
-    }
-    
-}
-
-/**
- * @uri /data/\w+/\w+ 
- */
-class DataObjectResource extends Resource {
-
-    function getTypeAndUid($request) {
-        $uri = get_clean_uri($request);
-        $path = explode('/', $uri);
-        $type = $path[2];
-        $uid = $path[3];
-        return array('type' => $type, 'uid' => $uid);
-    }
-
-    function get($request) {
-        $response = new Response($request);
-        restore_session($response);
-
-        $info = $this->getTypeAndUid($request);
-        $objects = $info['type']::get(array('uid' => $info['uid']));
-        if (empty($objects)) {
-            throw new ResponseException("Object not found", Response::NOTFOUND);
-        }
-
-        $response->body = $objects[0];
-        return $response;
-    }
-
-    function post($request) {
-        $response = new Response($request);
-        restore_session($response);
-
-        $info = $this->getTypeAndUid($request);
-        $onlyAdd = $request->ifNoneMatch('*');
-        $onlyUpdate = $request->ifMatch('*');
-
-        $object = FALSE;
-        $objects = $info['type']::get(array('uid' => $info['uid']));
-        if (!empty($objects)) {
-            $object = $objects[0];
-        }
-
-        if (( $onlyUpdate && !$object ) || ( $onlyAdd && $object )) {
-            throw new ResponseException("Update/Create and existing object mismatch", Response::PRECONDITIONFAILED);
-        }
-
-        if (!$object) {
-            $object = new $info['type']($info->uid);
-            $response->code = Response::CREATED;
-        } else {
-            $response->code = Response::OK;
-        }
-        foreach ($request->data as $key => $val) {
-            $object->$key = $val;
+        if (isset($object->creator)) {
+            $object->creator = $user;
         }
         if (!$object->save()) {
