Skip to content

Commit e9a608f

Browse files
committed
minor #18967 [HttpFoundation] Support root-level Generator in StreamedJsonResponse (alexandre-daubois)
This PR was merged into the 6.4 branch. Discussion ---------- [HttpFoundation] Support root-level Generator in StreamedJsonResponse Fix * #18954 Commits ------- 345d334 [HttpFoundation] Support root-level Generator in StreamedJsonResponse
2 parents 59576af + 345d334 commit e9a608f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

components/http_foundation.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,28 @@ after some specific item count to send the contents to the browser::
709709
}
710710
}
711711

712+
You also have the possibility to directly pass any iterable to
713+
``StreamedJsonResponse``, including generators::
714+
715+
public function loadArticles(): \Generator
716+
{
717+
yield ['title' => 'Article 1'];
718+
yield ['title' => 'Article 2'];
719+
yield ['title' => 'Article 3'];
720+
}
721+
722+
public function __invoke(): Response
723+
{
724+
// ...
725+
726+
return new StreamedJsonResponse(loadArticles());
727+
}
728+
729+
.. versionadded:: 6.4
730+
731+
The support for any iterable in ``StreamedJsonResponse`` was introduced in
732+
Symfony 6.4.
733+
712734
.. _component-http-foundation-serving-files:
713735

714736
Serving Files

0 commit comments

Comments
 (0)