aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTom Needham <needham.thomas@gmail.com>2012-12-11 22:36:46 +0000
committerTom Needham <needham.thomas@gmail.com>2012-12-11 22:36:46 +0000
commit115dbc721d77509274e7a1bacf0239ada565b005 (patch)
tree31e771c7c48b120fd0d2f8f01f6bfd76bd00f77f /lib
parent43917e187b91d8b235c37fa873de306f83e61b36 (diff)
downloadnextcloud-server-115dbc721d77509274e7a1bacf0239ada565b005.tar.gz
nextcloud-server-115dbc721d77509274e7a1bacf0239ada565b005.zip
API: Specify the response format using a GET parameter
Diffstat (limited to 'lib')
-rw-r--r--lib/api.php14
1 files changed, 5 insertions, 9 deletions
diff --git a/lib/api.php b/lib/api.php
index d11c3799d9a..cc1d9fccaff 100644
--- a/lib/api.php
+++ b/lib/api.php
@@ -66,10 +66,8 @@ class OC_API {
$name = str_replace(array('/', '{', '}'), '_', $name);
if(!isset(self::$actions[$name])){
OC::getRouter()->useCollection('ocs');
- OC::getRouter()->create($name, $url.'.{_format}')
+ OC::getRouter()->create($name, $url)
->method($method)
- ->defaults(array('_format' => 'xml') + $defaults)
- ->requirements(array('_format' => 'xml|json') + $requirements)
->action('OC_API', 'call');
self::$actions[$name] = array();
}
@@ -106,11 +104,9 @@ class OC_API {
// Merge the responses
$response = self::mergeResponses($responses);
// Send the response
- if(isset($parameters['_format'])){
- self::respond($response, $parameters['_format']);
- } else {
- self::respond($response);
- }
+ $formats = array('json', 'xml');
+ $format = !empty($_GET['format']) && in_array($_GET['format'], $formats) ? $_GET['format'] : 'xml';
+ self::respond($response, $format);
// logout the user to be stateless
OC_User::logout();
}
@@ -218,7 +214,7 @@ class OC_API {
* @param int|array $response the response
* @param string $format the format xml|json
*/
- private static function respond($response, $format='json'){
+ private static function respond($response, $format='xml'){
if ($format == 'json') {
OC_JSON::encodedPrint($response);
} else if ($format == 'xml') {