Skip to content

Commit ce278ab

Browse files
committed
[HttpFoundation] Adding a note about JSON responses, which I'll update for the JsonResponse in 2.1
1 parent f8a393b commit ce278ab

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

components/http_foundation/introduction.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,21 @@ To redirect the client to another URL, you can use the
350350

351351
$response = new RedirectResponse('http://example.com/');
352352

353+
Creating a JSON Response
354+
~~~~~~~~~~~~~~~~~~~~~~~~
355+
356+
Any type of response can be created via the
357+
:class:`Symfony\\Component\\HttpFoundation\\Response` class by setting the
358+
right content and headers. A JSON response might look like this::
359+
360+
use Symfony\Component\HttpFoundation\Response;
361+
362+
$response = new Response();
363+
$response->setContent(json_encode(array(
364+
'data' => 123
365+
)));
366+
$response->headers->set('Content-Type', 'application/json');
367+
353368
Session
354369
-------
355370

0 commit comments

Comments
 (0)