Skip to main content
Version: 1.18

APIRequest

Exposes API that can be used for the Web API testing. Each Playwright browser context has a APIRequestContext instance attached which shares cookies with the page context. Its also possible to create a new APIRequestContext instance manually. For more information see here.

APIRequest.newContext([options])

  • options <ApiRequest.NewContextOptions>
    • setBaseURL <String> Methods like APIRequestContext.get(url[, options]) take the base URL into consideration by using the 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
    • setExtraHTTPHeaders <Map<String, String>> An object containing additional HTTP headers to be sent with every request.#
    • setHttpCredentials <HttpCredentials> Credentials for HTTP authentication.#
    • setIgnoreHTTPSErrors <boolean> Whether to ignore HTTPS errors when sending network requests. Defaults to false.#
    • setProxy <Proxy> Network proxy settings.#
      • setServer <String> Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example http://myproxy.com:3128 or socks5://myproxy.com:3128. Short form myproxy.com:3128 is considered an HTTP proxy.
      • setBypass <String> Optional comma-separated domains to bypass proxy, for example ".com, chromium.org, .domain.com".
      • setUsername <String> Optional username to use if HTTP proxy requires authentication.
      • setPassword <String> Optional password to use if HTTP proxy requires authentication.
    • setStorageState <String> Populates context with given storage state. This option can be used to initialize context with logged-in information obtained via BrowserContext.storageState([options]) or APIRequestContext.storageState([options]). Either a path to the file with saved storage, or the value returned by one of BrowserContext.storageState([options]) or APIRequestContext.storageState([options]) methods.#
    • setStorageStatePath <Path> Populates context with given storage state. This option can be used to initialize context with logged-in information obtained via BrowserContext.storageState([options]). Path to the file with saved storage state.#
    • setTimeout <double> Maximum time in milliseconds to wait for the response. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.#
    • setUserAgent <String> Specific user agent to use in this context.#
  • returns: <APIRequestContext>#

Creates new instances of APIRequestContext.