<p dir="auto">It would be great to have following features at APIRequest</p>
<ol dir="auto">
<li>generics for APIRequestContext methods and for APIResponse, like <code class="notranslate">APIRequestContext.get&lt;T&gt;(url, options): Promise&lt;APIResponse&lt;T&gt;&gt;</code> since it's often much more convenient than using assert or casting <code class="notranslate">any</code> to desired type manually</li>
<li>ability to set default value for <code class="notranslate">failOnStatusCode</code> globally, in beforeEach block or per context instance, since it's often to be used with .json() in order to get JS response body, and json conversion would often get xml error and throw error trying to parse it with not informative message like <code class="notranslate">SyntaxError: Unexpected token &lt; in JSON at position 0</code> instead of actuial API error description</li>
<li>introduce APIRequestContext methods overloads. It's quite often for testing we don't care about post response except it successful, but when we do we often want to get response body, and it's not quite convenient additionally <code class="notranslate">await APIResponse.json()</code>. So it might be useful to be able to define what kind of response do we want to get. For example, Angular httpClient uses  options.observe property for this purpose <a href="https://github.com/angular/angular/blob/master/packages/common/http/src/client.ts#L1209">https://github.com/angular/angular/blob/master/packages/common/http/src/client.ts#L1209</a></li>
</ol>
<p dir="auto">sorry if some feature requests duplicate, originally I was looking only for failOnStatusCode, but got a little carried away 🙂</p>
<h3 dir="auto">System info</h3>
<ul dir="auto">
<li>Playwright Version: v1.33</li>
<li>Operating System: Docker container</li>
<li>Browser: [All, Chromium, Firefox, WebKit]</li>
<li>Other info:<br>
an error "SystemError [ERR_SYSTEM_ERROR]: A system error occurred: uv_os_get_passwd returned ENOENT (no such file or directory)" that could occur when there is no /etc/passwd entry for the current user, such as in some Docker and GitHub Action setups.</li>
</ul>
<p dir="auto">the issue is introduced by the PR <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1644832988" data-permission-text="Title is private" data-url="https://github.com/microsoft/playwright/issues/22046" data-hovercard-type="pull_request" data-hovercard-url="/microsoft/playwright/pull/22046/hovercard" href="https://github.com/microsoft/playwright/pull/22046">#22046</a>.<br>
Cypress had same issue before, they had a fix <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="953303563" data-permission-text="Title is private" data-url="https://github.com/cypress-io/cypress/issues/17488" data-hovercard-type="pull_request" data-hovercard-url="/cypress-io/cypress/pull/17488/hovercard" href="https://github.com/cypress-io/cypress/pull/17488">cypress-io/cypress#17488</a>.</p>
<h3 dir="auto">Source code</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I provided exact source code that allows reproducing the issue locally.</li>
</ul>




<p dir="auto"><strong>Link to the GitHub repository with the repro</strong></p>
<p dir="auto"><a href="https://github.com/pei-wang/playwright-issue-reproduce">https://github.com/pei-wang/playwright-issue-reproduce</a></p>
<p dir="auto"><strong>Steps</strong></p>
<ul dir="auto">
<li>[Run the test]</li>
</ul>
<p dir="auto"><strong>Expected</strong></p>
<p dir="auto">run tests successfully</p>
<p dir="auto"><strong>Actual</strong></p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/7090689/235289626-27097b21-e089-48e6-933b-fe3e5523bd4d.png"><img width="1541" alt="CleanShot 2023-04-29 at 19 23 30@2x" src="https://user-images.githubusercontent.com/7090689/235289626-27097b21-e089-48e6-933b-fe3e5523bd4d.png" style="max-width: 100%;"></a></p>