diff --git a/lib/api.php b/lib/api.php
index fd2c621f389c084b423d9a8f807e61e07d0a6fa2..515bab6714e042d1d69b70ff77161568254dd815 100644
--- a/lib/api.php
+++ b/lib/api.php
@@ -43,7 +43,8 @@ class OC_API {
 		$name = str_replace(array('/', '{', '}'), '_', $name);
 		if(!isset(self::$actions[$name])){
 			OC::$router->create($name, $url.'.{_format}')
-				->defaults(array('_format'=>'xml'))
+				->defaults(array('_format' => 'xml'))
+				->requirements(array('_format' => 'xml|json'))
 				->action('OC_API', 'call');
 			self::$actions[$name] = array();
 		}
@@ -55,7 +56,7 @@ class OC_API {
 	* @param array $parameters
 	*/
 	public static function call($parameters){
-		$name = $parameters['_name'];
+		$name = $parameters['_route'];
 		// Loop through registered actions
 		foreach(self::$actions[$name] as $action){
 			$app = $action['app'];
@@ -107,8 +108,14 @@ class OC_API {
 	* @param int|array $response the response
 	* @param string $format the format xml|json
 	*/
-	private function respond($response, $format='json'){
-		// TODO respond in the correct format
+	private static function respond($response, $format='json'){
+		if ($format == 'json') {
+			echo json_encode($response);
+		} else if ($format == 'xml') {
+			// TODO array to xml
+		} else {
+			var_dump($format, $response);
+		}
 	}
 	
-}
\ No newline at end of file
+}
diff --git a/lib/app.php b/lib/app.php
index 60bd0ef476bff4b1933015fd5fa184ea28b1a607..7863153d9b9cd4156f72c714ad19d8334668dad3 100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -145,7 +145,7 @@ class OC_App{
 	 * @param string $appid the id of the app to check
 	 * @return bool
 	 */
-	public function isShipped($appid){
+	public static function isShipped($appid){
 		$info = self::getAppInfo($appid);
 		if(isset($info['shipped']) && $info['shipped']=='true'){
 			return true;
diff --git a/lib/ocs.php b/lib/ocs.php
index d7a7951fab53d3f453a87569ef6387e1a0a65c5c..780fd4a65816c1da51673db64d3692505e10528c 100644
--- a/lib/ocs.php
+++ b/lib/ocs.php
@@ -251,6 +251,24 @@ class OC_OCS {
 		exit();
 	}
 
+	public static function notFound() {
+		if($_SERVER['REQUEST_METHOD'] == 'GET') {
+			$method='get';
+		}elseif($_SERVER['REQUEST_METHOD'] == 'PUT') {
+			$method='put';
+			parse_str(file_get_contents("php://input"),$put_vars);
+		}elseif($_SERVER['REQUEST_METHOD'] == 'POST') {
+			$method='post';
+		}else{
+			echo('internal server error: method not supported');
+			exit();
+		}
+		$format = self::readData($method, 'format', 'text', '');
+		$txt='Invalid query, please check the syntax. API specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n";
+		$txt.=OC_OCS::getDebugOutput();
+		echo(OC_OCS::generateXml($format,'failed',999,$txt));
+	}
+
 	/**
 	* generated some debug information to make it easier to find faild API calls
 	* @return debug data string
diff --git a/ocs/v1.php b/ocs/v1.php
index ab0dc80f4ba9faa38c772a723e67c136dd7a7a50..4580221e600d3ed5a7b1746a77a4b57bf0c7e4a2 100644
--- a/ocs/v1.php
+++ b/ocs/v1.php
@@ -22,5 +22,13 @@
 */
 
 require_once('../lib/base.php');
-@ob_clean();
-OC_OCS::handle();
+use Symfony\Component\Routing\Exception\ResourceNotFoundException;
+
+OC::$router->useCollection('ocs');
+OC::$router->loadRoutes();
+
+try {
+	OC::$router->match($_SERVER['PATH_INFO']);
+} catch (ResourceNotFoundException $e) {
+	OC_OCS::notFound();
+}