On this page
APIRequest
Exposes API that can be used for the Web API testing. This class is used for creating APIRequestContext instance which in turn can be used for sending web requests. An instance of this class can be obtained via playwright.request. For more information see APIRequestContext.
Methods
newContext
Creates new instances of APIRequestContext.
Usage
await apiRequest.newContext();
await apiRequest.newContext(options);
Arguments
optionsObject (optional)baseURLstring (optional)Methods like apiRequestContext.get() take the base URL into consideration by using the
URL()constructor for building the corresponding URL. Examples:- baseURL:
http://localhost:3000and sending request to/bar.htmlresults inhttp://localhost:3000/bar.html - baseURL:
http://localhost:3000/foo/and sending request to./bar.htmlresults inhttp://localhost:3000/foo/bar.html - baseURL:
http://localhost:3000/foo(without trailing slash) and navigating to./bar.htmlresults inhttp://localhost:3000/bar.html
- baseURL:
extraHTTPHeadersObject<string, string> (optional)An object containing additional HTTP headers to be sent with every request. Defaults to none.
httpCredentialsObject (optional)usernamestringpasswordstringoriginstring (optional)Restrain sending http credentials on specific origin (scheme://host:port).
Credentials for HTTP authentication. If no origin is specified, the username and password are sent to any servers upon unauthorized responses.
ignoreHTTPSErrorsboolean (optional)Whether to ignore HTTPS errors when sending network requests. Defaults to
false.proxyObject (optional)serverstringProxy to be used for all requests. HTTP and SOCKS proxies are supported, for example
http://myproxy.com:3128orsocks5://myproxy.com:3128. Short formmyproxy.com:3128is considered an HTTP proxy.bypassstring (optional)Optional comma-separated domains to bypass proxy, for example
".com, chromium.org, .domain.com".usernamestring (optional)Optional username to use if HTTP proxy requires authentication.
passwordstring (optional)Optional password to use if HTTP proxy requires authentication.
Network proxy settings.
storageStatestring | Object (optional)Populates context with given storage state. This option can be used to initialize context with logged-in information obtained via browserContext.storageState() or apiRequestContext.storageState(). Either a path to the file with saved storage, or the value returned by one of browserContext.storageState() or apiRequestContext.storageState() methods.
timeoutnumber (optional)Maximum time in milliseconds to wait for the response. Defaults to
30000(30 seconds). Pass0to disable timeout.userAgentstring (optional)Specific user agent to use in this context.
Returns
© 2024 Microsoft
Licensed under the Apache License, Version 2.0.
https://playwright.dev/docs/api/class-apirequest