From ed704e6a3bcd24c9d0ffbc4e71d2441aba4e9d0b Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 16 Jul 2010 12:16:20 -0700 Subject: Trap 404s and return Rest_Exception instead. Fixes ticket #1213. --- modules/rest/controllers/rest.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'modules/rest/controllers') diff --git a/modules/rest/controllers/rest.php b/modules/rest/controllers/rest.php index f8a46515..293252ef 100644 --- a/modules/rest/controllers/rest.php +++ b/modules/rest/controllers/rest.php @@ -87,6 +87,8 @@ class Rest_Controller extends Controller { // 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 -- cgit v1.2.3 From 71a32e4e2453b8e6dec922e88180960a3a5b9aec Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 16 Jul 2010 14:23:03 -0700 Subject: POST requests create a new entity and should result in a 201 Created reply with a Location field that matches the URL of the newly created resource. Fixes ticket #1178. --- modules/rest/controllers/rest.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'modules/rest/controllers') diff --git a/modules/rest/controllers/rest.php b/modules/rest/controllers/rest.php index 293252ef..bf2f0a54 100644 --- a/modules/rest/controllers/rest.php +++ b/modules/rest/controllers/rest.php @@ -81,6 +81,11 @@ 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 -- cgit v1.2.3