diff options
Diffstat (limited to 'modules/rest')
-rw-r--r-- | modules/rest/controllers/rest.php | 7 | ||||
-rw-r--r-- | modules/rest/helpers/rest.php | 3 | ||||
-rw-r--r-- | modules/rest/tests/Rest_Controller_Test.php | 8 | ||||
-rw-r--r-- | modules/rest/views/user_profile_rest.html.php | 12 |
4 files changed, 19 insertions, 11 deletions
diff --git a/modules/rest/controllers/rest.php b/modules/rest/controllers/rest.php index f8a46515..bf2f0a54 100644 --- a/modules/rest/controllers/rest.php +++ b/modules/rest/controllers/rest.php @@ -81,12 +81,19 @@ class Rest_Controller extends Controller { } $response = call_user_func(array($handler_class, $handler_method), $request); + if ($handler_method == "post") { + // post methods must return a response containing a URI. + header("HTTP/1.1 201 Created"); + header("Location: {$response['url']}"); + } rest::reply($response); } catch (ORM_Validation_Exception $e) { // Note: this is totally insufficient because it doesn't take into account localization. We // either need to map the result values to localized strings in the application code, or every // client needs its own l10n string set. throw new Rest_Exception("Bad Request", 400, $e->validation->errors()); + } catch (Kohana_404_Exception $e) { + throw new Rest_Exception("Not Found", 404); } } }
\ No newline at end of file diff --git a/modules/rest/helpers/rest.php b/modules/rest/helpers/rest.php index bcb12d58..644779da 100644 --- a/modules/rest/helpers/rest.php +++ b/modules/rest/helpers/rest.php @@ -35,8 +35,7 @@ class rest_Core { } print "<pre>$html</pre>"; } else { - header("Content-type: application/json"); - print json_encode($data); + json::reply($data); } } diff --git a/modules/rest/tests/Rest_Controller_Test.php b/modules/rest/tests/Rest_Controller_Test.php index 0c8a4a98..43139d29 100644 --- a/modules/rest/tests/Rest_Controller_Test.php +++ b/modules/rest/tests/Rest_Controller_Test.php @@ -142,8 +142,8 @@ class Rest_Controller_Test extends Gallery_Unit_Test_Case { } class mock_rest { - static function get($request) { return $request; } - static function post($request) { return $request; } - static function put($request) { return $request; } - static function delete($request) { return $request; } + static function get($request) { return (array)$request; } + static function post($request) { return (array)$request; } + static function put($request) { return (array)$request; } + static function delete($request) { return (array)$request; } }
\ No newline at end of file diff --git a/modules/rest/views/user_profile_rest.html.php b/modules/rest/views/user_profile_rest.html.php index 397afa89..e81f3d0b 100644 --- a/modules/rest/views/user_profile_rest.html.php +++ b/modules/rest/views/user_profile_rest.html.php @@ -1,8 +1,10 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> <div id="g-rest-detail"> -<ul> - <li id="g-rest-key"> - <p><b><?= t("Key") ?></b>:<?= html::clean($rest_key) ?></p> - </li> -</ul> + <ul> + <li id="g-rest-key"> + <p> + <?= t("<b>Key</b>: %key", array("key" => $rest_key)) ?> + </p> + </li> + </ul> </div> |