From 578cbcef439f95afacedd65183778f61cf7f1ee2 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Fri, 28 Feb 2025 15:21:41 +0100 Subject: [PATCH] Move section JSON Signed-off-by: Christian Wolf --- developer_manual/basics/controllers.rst | 79 ++++++++++++------------- 1 file changed, 38 insertions(+), 41 deletions(-) diff --git a/developer_manual/basics/controllers.rst b/developer_manual/basics/controllers.rst index ad133f55d..fcecdabb8 100644 --- a/developer_manual/basics/controllers.rst +++ b/developer_manual/basics/controllers.rst @@ -482,6 +482,44 @@ Now your method will be reachable via ``/ocs/v2.php/apps//api/v JSON ^^^^ +Returning JSON is simple, just pass an array to a JSONResponse: + +.. code-block:: php + + 'hi'); + return new JSONResponse($params); + } + + } + +Because returning JSON is such a common task, there's even a shorter way to do this: + +.. code-block:: php + + 'hi'); + } + + } + +Why does this work? Because the dispatcher sees that the controller did not return a subclass of a Response and asks the controller to turn the value into a Response. That's where responders come in. + Handling errors ^^^^^^^^^^^^^^^ @@ -524,47 +562,6 @@ Modifying the content security policy --- -JSON -^^^^ - -Returning JSON is simple, just pass an array to a JSONResponse: - -.. code-block:: php - - 'hi'); - return new JSONResponse($params); - } - - } - -Because returning JSON is such a common task, there's even a shorter way to do this: - -.. code-block:: php - - 'hi'); - } - - } - -Why does this work? Because the dispatcher sees that the controller did not return a subclass of a Response and asks the controller to turn the value into a Response. That's where responders come in. - Responders ^^^^^^^^^^