APIRequest.new_context
Creates new instances of `APIRequestContext`.
Parameters
----------
base_url : Union[str, None]
Methods like `a_pi_request_context.get()` take the base URL into consideration by using the
[`URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor for building the corresponding URL.
Examples:
- baseURL: `http://localhost:3000` and sending request to `/bar.html` results in `http://localhost:3000/bar.html`
- baseURL: `http://localhost:3000/foo/` and sending request to `./bar.html` results in
`http://localhost:3000/foo/bar.html`
- baseURL: `http://localhost:3000/foo` (without trailing slash) and navigating to `./bar.html` results in
`http://localhost:3000/bar.html`
extra_http_headers : Union[Dict[str, str], None]
An object containing additional HTTP headers to be sent with every request. Defaults to none.
http_credentials : Union[{username: str, password: str, origin: Union[str, None], send: Union["always", "unauthorized", None]}, None]
Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication). If no
origin is specified, the username and password are sent to any servers upon unauthorized responses.
ignore_https_errors : Union[bool, None]
Whether to ignore HTTPS errors when sending network requests. Defaults to `false`.
proxy : Union[{server: str, bypass: Union[str, None], username: Union[str, None], password: Union[str, None]}, None]
Network proxy settings.
user_agent : Union[str, None]
Specific user agent to use in this context.
timeout : Union[float, None]
Maximum time in milliseconds to wait for the response. Defaults to `30000` (30 seconds). Pass `0` to disable
timeout.
storage_state : Union[pathlib.Path, str, {cookies: Sequence[{name: str, value: str, domain: str, path: str, expires: float, httpOnly: bool, secure: bool, sameSite: Union["Lax", "None", "Strict"]}], origins: Sequence[{origin: str, localStorage: Sequence[{name: str, value: str}]}]}, None]
Populates context with given storage state. This option can be used to initialize context with logged-in
information obtained via `browser_context.storage_state()` or `a_pi_request_context.storage_state()`.
Either a path to the file with saved storage, or the value returned by one of
`browser_context.storage_state()` or `a_pi_request_context.storage_state()` methods.
client_certificates : Union[Sequence[{origin: str, certPath: Union[pathlib.Path, str, None], cert: Union[bytes, None], keyPath: Union[pathlib.Path, str, None], key: Union[bytes, None], pfxPath: Union[pathlib.Path, str, None], pfx: Union[bytes, None], passphrase: Union[str, None]}], None]
TLS Client Authentication allows the server to request a client certificate and verify it.
**Details**
An array of client certificates to be used. Each certificate object must have either both `certPath` and `keyPath`,
a single `pfxPath`, or their corresponding direct value equivalents (`cert` and `key`, or `pfx`). Optionally,
`passphrase` property should be provided if the certificate is encrypted. The `origin` property should be provided
with an exact match to the request origin that the certificate is valid for.
Client certificate authentication is only active when at least one client certificate is provided. If you want to
reject all client certificates sent by the server, you need to provide a client certificate with an `origin` that
does not match any of the domains you plan to visit.
**NOTE** When using WebKit on macOS, accessing `localhost` will not pick up client certificates. You can make it
work by replacing `localhost` with `local.playwright`.
fail_on_status_code : Union[bool, None]
Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status
codes.
max_redirects : Union[int, None]
Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is
exceeded. Defaults to `20`. Pass `0` to not follow redirects. This can be overwritten for each request
individually.
Returns
-------
APIRequestContext