Web Services Tutorial Code / public / rest / index.php

Diff from to


-// inclue the various view classes
+// include the various view classes
     $view = new JsonView();
+// grab incoming parameters
+$data = array();
+switch($verb) {
+    case 'GET':
+        parse_str($_SERVER['QUERY_STRING'], &$data);
+        break;
+    case 'POST':
+    case 'PUT':
+        // incoming JSON data, it's an array
+        $data = json_decode(file_get_contents('php://input'), true);
+        break;
+    case 'DELETE':
+        // do nothing
+        break;
+    default:
+        // WTF?
+        break;
 // route the request
+$path = explode('/',$_SERVER['PATH_INFO']);
 $action_name = strtoupper($verb) . 'Action';
-$url_params = explode('/',$_SERVER['PATH_INFO']);
-$controller_name = ucfirst($url_params[1]) . 'Controller';
+$controller_name = ucfirst($path[1]) . 'Controller';
 $controller = new $controller_name();
-$data = $controller->$action_name($url_params);
+$data = $controller->$action_name($path, $data);
 // output appropriately
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.