Interface 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.

Hierarchy

  • APIRequest

Methods

Methods

  • Creates new instances of APIRequestContext.

    Parameters

    • Optional options: {
          baseURL?: string;
          clientCertificates?: {
              cert?: Buffer;
              certPath?: string;
              key?: Buffer;
              keyPath?: string;
              origin: string;
              passphrase?: string;
              pfx?: Buffer;
              pfxPath?: string;
          }[];
          extraHTTPHeaders?: {
              [key: string]: string;
          };
          httpCredentials?: {
              origin?: string;
              password: string;
              send?: "unauthorized" | "always";
              username: string;
          };
          ignoreHTTPSErrors?: boolean;
          proxy?: {
              bypass?: string;
              password?: string;
              server: string;
              username?: string;
          };
          storageState?: string | {
              cookies: {
                  domain: string;
                  expires: number;
                  httpOnly: boolean;
                  name: string;
                  path: string;
                  sameSite: "Strict" | "Lax" | "None";
                  secure: boolean;
                  value: string;
              }[];
              origins: {
                  localStorage: {
                      name: string;
                      value: string;
                  }[];
                  origin: string;
              }[];
          };
          timeout?: number;
          userAgent?: string;
      }
      Optional
      • Optional baseURL?: 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
      • Optional clientCertificates?: {
            cert?: Buffer;
            certPath?: string;
            key?: Buffer;
            keyPath?: string;
            origin: string;
            passphrase?: string;
            pfx?: Buffer;
            pfxPath?: string;
        }[]

        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.

        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.

      • Optional extraHTTPHeaders?: {
            [key: string]: string;
        }

        An object containing additional HTTP headers to be sent with every request. Defaults to none.

        • [key: string]: string
      • Optional httpCredentials?: {
            origin?: string;
            password: string;
            send?: "unauthorized" | "always";
            username: string;
        }

        Credentials for HTTP authentication. If no origin is specified, the username and password are sent to any servers upon unauthorized responses.

        • Optional origin?: string

          Restrain sending http credentials on specific origin (scheme://host:port).

        • password: string
        • Optional send?: "unauthorized" | "always"

          This option only applies to the requests sent from corresponding APIRequestContext and does not affect requests sent from the browser. 'always' - Authorization header with basic authentication credentials will be sent with the each API request. 'unauthorized - the credentials are only sent when 401 (Unauthorized) response with WWW-Authenticate header is received. Defaults to 'unauthorized'.

        • username: string
      • Optional ignoreHTTPSErrors?: boolean

        Whether to ignore HTTPS errors when sending network requests. Defaults to false.

      • Optional proxy?: {
            bypass?: string;
            password?: string;
            server: string;
            username?: string;
        }

        Network proxy settings.

        • Optional bypass?: string

          Optional comma-separated domains to bypass proxy, for example ".com, chromium.org, .domain.com".

        • Optional password?: string

          Optional password to use if HTTP proxy requires authentication.

        • server: 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.

        • Optional username?: string

          Optional username to use if HTTP proxy requires authentication.

      • Optional storageState?: string | {
            cookies: {
                domain: string;
                expires: number;
                httpOnly: boolean;
                name: string;
                path: string;
                sameSite: "Strict" | "Lax" | "None";
                secure: boolean;
                value: string;
            }[];
            origins: {
                localStorage: {
                    name: string;
                    value: string;
                }[];
                origin: 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.

      • Optional timeout?: number

        Maximum time in milliseconds to wait for the response. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.

      • Optional userAgent?: string

        Specific user agent to use in this context.

    Returns Promise<APIRequestContext>

Generated using TypeDoc