Commit aee65e34 authored by Igor Wiedler's avatar Igor Wiedler

[json] add docs to the usage page

parent b2566895
...@@ -523,6 +523,26 @@ you can create by calling the ``redirect`` method:: ...@@ -523,6 +523,26 @@ you can create by calling the ``redirect`` method::
This will redirect from ``/`` to ``/hello``. This will redirect from ``/`` to ``/hello``.
JSON
----
If you want to return JSON data, you can use the ``json`` helper method.
Simply pass it your data, status code and headers, and it will create a
JSON response for you.
.. code-block:: php
$app->get('/users/{id}', function ($id) use ($app) {
$user = getUser($id);
if (!$user) {
$error = array('message' => 'The user was not found.');
return $app->json($error, 404);
}
return $app->json($user);
});
Streaming Streaming
--------- ---------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment