← All notes

APIRequestContext sends HTTP requests from Playwright without loading a page

Answer: Playwright can call a server's HTTP API directly from Node.js, without loading a page or running JavaScript in a browser. APIRequestContext is the object that sends those requests. Use it to test the API itself, to set up server state before a UI test, or to check post-conditions after browser actions.

The request fixture

Playwright Test ships a request fixture that already honors config such as baseURL and extraHTTPHeaders. In a test you can request.post(...) or request.get(...) and then assert with ok() or json(). Set baseURL and extraHTTPHeaders in the configuration file, or with test.use() in the test file itself.

If tests run behind a proxy, set use.proxy in the config and the request fixture picks it up.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Playwright docs, API testing, Apache-2.0 (https://raw.githubusercontent.com/microsoft/playwright/main/LICENSE). Copyright (c) Microsoft Corporation; microsoft/playwright (GitHub), api-testing-js.md (Playwright source docs), Apache-2.0 (https://raw.githubusercontent.com/microsoft/playwright/main/LICENSE). Copyright (c) Microsoft Corporation. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Playwright docs, API testing, Apache-2.0 (https://raw.githubusercontent.com/microsoft/playwright/main/LICENSE). Copyright (c) Microsoft Corporation; microsoft/playwright (GitHub), api-testing-js.md (Playwright source docs), Apache-2.0 (https://raw.githubusercontent.com/microsoft/playwright/main/LICENSE). Copyright (c) Microsoft Corporation.

Cite this

Permanent ID: iil:note:vskawem0

iinventedlight. 2026. "APIRequestContext sends HTTP requests from Playwright without loading a page." iinventedlight Library, iil:note:vskawem0, version of 2026-11-17. https://iinventedlight.com/library/notes/playwright-api-testing/. License: CC-BY-4.0.

@misc{iil_note_vskawem0,
  author = {{iinventedlight}},
  title = {{APIRequestContext sends HTTP requests from Playwright without loading a page}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-17},
  url = {https://iinventedlight.com/library/notes/playwright-api-testing/},
  note = {Permanent ID iil:note:vskawem0. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/playwright-api-testing.md.