Skip to content

Commit b80315c

Browse files
committed
feature #14804 [BrowserKit] Document the jsonRequest() method (javiereguiluz)
This PR was merged into the 5.3-dev branch. Discussion ---------- [BrowserKit] Document the jsonRequest() method Fixes #14534. Commits ------- c3cadab [BrowserKit] Document the jsonRequest() method
2 parents 3d022eb + c3cadab commit b80315c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

components/browser_kit.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ The value returned by the ``request()`` method is an instance of the
8080
:doc:`DomCrawler component </components/dom_crawler>`, which allows accessing
8181
and traversing HTML elements programmatically.
8282

83+
The :method:`Symfony\\Component\\BrowserKit\\AbstractBrowser::jsonRequest` method,
84+
which defines the same arguments as the ``request()`` method, is a shortcut to
85+
convert the request parameters into a JSON string and set the needed HTTP headers::
86+
87+
use Acme\Client;
88+
89+
$client = new Client();
90+
// this encodes parameters as JSON and sets the required CONTENT_TYPE and HTTP_ACCEPT headers
91+
$crawler = $client->jsonRequest('GET', '/', ['some_parameter' => 'some_value']);
92+
93+
.. versionadded:: 5.3
94+
95+
The ``jsonRequest()`` method was introduced in Symfony 5.3.
96+
8397
The :method:`Symfony\\Component\\BrowserKit\\AbstractBrowser::xmlHttpRequest` method,
8498
which defines the same arguments as the ``request()`` method, is a shortcut to
8599
make AJAX requests::

0 commit comments

Comments
 (0)