Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Sets up example folder with example from Readme.

commit 9f8d934511e233f557a7db79ad14000b39f28916 1 parent 4d06fba
@jacwright authored
View
0  sample.htaccess → example/.htaccess
File renamed without changes
View
59 example/TestController.php
@@ -0,0 +1,59 @@
+<?php
+
+class TestController
+{
+ /**
+ * Returns a JSON string object to the browser when hitting the root of the domain
+ *
+ * @url GET /
+ */
+ public function test()
+ {
+ return "Hello World";
+ }
+
+ /**
+ * Logs in a user with the given username and password POSTed. Though true
+ * REST doesn't believe in sessions, it is often desirable for an AJAX server.
+ *
+ * @url POST /login
+ */
+ public function login()
+ {
+ $username = $_POST['username'];
+ $password = $_POST['password'];
+ return array("success" => "Logged in " . $username);
+ }
+
+ /**
+ * Gets the user by id or current user
+ *
+ * @url GET /users/$id
+ * @url GET /users/current
+ */
+ public function getUser($id = null)
+ {
+ // if ($id) {
+ // $user = User::load($id); // possible user loading method
+ // } else {
+ // $user = $_SESSION['user'];
+ // }
+
+ return array("id" => $id, "name" => null); // serializes object into JSON
+ }
+
+ /**
+ * Saves a user to the database
+ *
+ * @url POST /users
+ * @url PUT /users/$id
+ */
+ public function saveUser($id = null, $data)
+ {
+ // ... validate $data properties such as $data->username, $data->firstName, etc.
+ // $data->id = $id;
+ // $user = User::saveUser($data); // saving the user to the database
+ $user = array("id" => $id, "name" => null);
+ return $user; // returning the updated or newly created user object
+ }
+}
View
8 example/index.php
@@ -0,0 +1,8 @@
+<?php
+
+require '../RestServer.php';
+require 'TestController.php';
+
+$server = new RestServer('debug');
+$server->addClass('TestController');
+$server->handle();
Please sign in to comment.
Something went wrong with that request. Please try again.