Permalink
Browse files

[json] add docs to the usage page

  • Loading branch information...
1 parent b256689 commit aee65e3453359d75963d0439743c6afd95cc83bd @igorw igorw committed Mar 20, 2012
Showing with 20 additions and 0 deletions.
  1. +20 −0 doc/usage.rst
View
20 doc/usage.rst
@@ -523,6 +523,26 @@ you can create by calling the ``redirect`` method::
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
---------

0 comments on commit aee65e3

Please sign in to comment.