effect-playwright
    Preparing search index...

    Interface APIRequestContext

    This API is used for the Web API testing. You can use it to trigger API endpoints, configure micro-services, prepare environment or the service to your e2e test.

    Each Playwright browser context has an associated APIRequestContext, accessible via browserContext.request or page.request (these return the

    same instancepage.request is a shortcut for page.context().request). You can also create a standalone, isolated instance with apiRequest.newContext([options]).

    Cookie management

    The APIRequestContext returned by browserContext.request and

    page.request uses the same cookie jar as its BrowserContext:

    If you want API requests that do not share cookies with the browser, create an isolated context via apiRequest.newContext([options]). Such APIRequestContext object will have its own isolated cookie storage.

    interface APIRequestContext {
        tracing: Tracing;
        "[asyncDispose]"(): Promise<void>;
        delete(
            url: string,
            options?: {
                data?: any;
                failOnStatusCode?: boolean;
                form?: { [key: string]: string | number | boolean } | FormData;
                headers?: { [key: string]: string };
                ignoreHTTPSErrors?: boolean;
                maxRedirects?: number;
                maxRetries?: number;
                multipart?:
                    | FormData
                    | {
                        [key: string]: | string
                        | number
                        | boolean
                        | ReadStream
                        | { buffer: Buffer; mimeType: string; name: string };
                    };
                params?: | string
                | { [key: string]: string
                | number
                | boolean }
                | URLSearchParams;
                signal?: AbortSignal;
                timeout?: number;
            },
        ): Promise<APIResponse>;
        dispose(options?: { reason?: string }): Promise<void>;
        fetch(
            urlOrRequest: string | Request,
            options?: {
                data?: any;
                failOnStatusCode?: boolean;
                form?: FormData | { [key: string]: string | number | boolean };
                headers?: { [key: string]: string };
                ignoreHTTPSErrors?: boolean;
                maxRedirects?: number;
                maxRetries?: number;
                method?: string;
                multipart?:
                    | FormData
                    | {
                        [key: string]: | string
                        | number
                        | boolean
                        | ReadStream
                        | { buffer: Buffer; mimeType: string; name: string };
                    };
                params?: | string
                | URLSearchParams
                | { [key: string]: string
                | number
                | boolean };
                signal?: AbortSignal;
                timeout?: number;
            },
        ): Promise<APIResponse>;
        get(
            url: string,
            options?: {
                data?: any;
                failOnStatusCode?: boolean;
                form?: FormData | { [key: string]: string | number | boolean };
                headers?: { [key: string]: string };
                ignoreHTTPSErrors?: boolean;
                maxRedirects?: number;
                maxRetries?: number;
                multipart?:
                    | FormData
                    | {
                        [key: string]: | string
                        | number
                        | boolean
                        | ReadStream
                        | { buffer: Buffer; mimeType: string; name: string };
                    };
                params?: | string
                | URLSearchParams
                | { [key: string]: string
                | number
                | boolean };
                signal?: AbortSignal;
                timeout?: number;
            },
        ): Promise<APIResponse>;
        head(
            url: string,
            options?: {
                data?: any;
                failOnStatusCode?: boolean;
                form?: FormData | { [key: string]: string | number | boolean };
                headers?: { [key: string]: string };
                ignoreHTTPSErrors?: boolean;
                maxRedirects?: number;
                maxRetries?: number;
                multipart?:
                    | FormData
                    | {
                        [key: string]: | string
                        | number
                        | boolean
                        | ReadStream
                        | { buffer: Buffer; mimeType: string; name: string };
                    };
                params?: | string
                | URLSearchParams
                | { [key: string]: string
                | number
                | boolean };
                signal?: AbortSignal;
                timeout?: number;
            },
        ): Promise<APIResponse>;
        patch(
            url: string,
            options?: {
                data?: any;
                failOnStatusCode?: boolean;
                form?: FormData | { [key: string]: string | number | boolean };
                headers?: { [key: string]: string };
                ignoreHTTPSErrors?: boolean;
                maxRedirects?: number;
                maxRetries?: number;
                multipart?:
                    | FormData
                    | {
                        [key: string]: | string
                        | number
                        | boolean
                        | ReadStream
                        | { buffer: Buffer; mimeType: string; name: string };
                    };
                params?: | string
                | URLSearchParams
                | { [key: string]: string
                | number
                | boolean };
                signal?: AbortSignal;
                timeout?: number;
            },
        ): Promise<APIResponse>;
        post(
            url: string,
            options?: {
                data?: any;
                failOnStatusCode?: boolean;
                form?: FormData | { [key: string]: string | number | boolean };
                headers?: { [key: string]: string };
                ignoreHTTPSErrors?: boolean;
                maxRedirects?: number;
                maxRetries?: number;
                multipart?:
                    | FormData
                    | {
                        [key: string]: | string
                        | number
                        | boolean
                        | ReadStream
                        | { buffer: Buffer; mimeType: string; name: string };
                    };
                params?: | string
                | URLSearchParams
                | { [key: string]: string
                | number
                | boolean };
                signal?: AbortSignal;
                timeout?: number;
            },
        ): Promise<APIResponse>;
        put(
            url: string,
            options?: {
                data?: any;
                failOnStatusCode?: boolean;
                form?: FormData | { [key: string]: string | number | boolean };
                headers?: { [key: string]: string };
                ignoreHTTPSErrors?: boolean;
                maxRedirects?: number;
                maxRetries?: number;
                multipart?:
                    | FormData
                    | {
                        [key: string]: | string
                        | number
                        | boolean
                        | ReadStream
                        | { buffer: Buffer; mimeType: string; name: string };
                    };
                params?: | string
                | URLSearchParams
                | { [key: string]: string
                | number
                | boolean };
                signal?: AbortSignal;
                timeout?: number;
            },
        ): Promise<APIResponse>;
        storageState(
            options?: { indexedDB?: boolean; path?: string },
        ): Promise<
            {
                cookies: {
                    domain: string;
                    expires: number;
                    httpOnly: boolean;
                    name: string;
                    path: string;
                    sameSite: "None"
                    | "Strict"
                    | "Lax";
                    secure: boolean;
                    value: string;
                }[];
                origins: {
                    localStorage: { name: string; value: string }[];
                    origin: string;
                }[];
            },
        >;
    }
    Index
    tracing: Tracing
    • Returns Promise<void>

    • Sends HTTP(S) DELETE request and returns its response. The method will populate request cookies from the context and update context cookies from the response. The method will automatically follow redirects.

      Parameters

      • url: string

        Target URL.

      • Optionaloptions: {
            data?: any;
            failOnStatusCode?: boolean;
            form?: { [key: string]: string | number | boolean } | FormData;
            headers?: { [key: string]: string };
            ignoreHTTPSErrors?: boolean;
            maxRedirects?: number;
            maxRetries?: number;
            multipart?:
                | FormData
                | {
                    [key: string]: | string
                    | number
                    | boolean
                    | ReadStream
                    | { buffer: Buffer; mimeType: string; name: string };
                };
            params?: | string
            | { [key: string]: string
            | number
            | boolean }
            | URLSearchParams;
            signal?: AbortSignal;
            timeout?: number;
        }
        • Optionaldata?: any

          Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and content-type header will be set to application/json if not explicitly set. Otherwise the content-type header will be set to application/octet-stream if not explicitly set.

        • OptionalfailOnStatusCode?: boolean

          Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.

        • Optionalform?: { [key: string]: string | number | boolean } | FormData

          Provides an object that will be serialized as html form using application/x-www-form-urlencoded encoding and sent as this request body. If this parameter is specified content-type header will be set to application/x-www-form-urlencoded unless explicitly provided.

        • Optionalheaders?: { [key: string]: string }

          Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by it.

        • OptionalignoreHTTPSErrors?: boolean

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

        • OptionalmaxRedirects?: number

          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.

        • OptionalmaxRetries?: number

          Maximum number of times network errors should be retried. Currently only ECONNRESET error is retried. Does not retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to 0 - no retries.

        • Optionalmultipart?:
              | FormData
              | {
                  [key: string]: | string
                  | number
                  | boolean
                  | ReadStream
                  | { buffer: Buffer; mimeType: string; name: string };
              }

          Provides an object that will be serialized as html form using multipart/form-data encoding and sent as this request body. If this parameter is specified content-type header will be set to multipart/form-data unless explicitly provided. File values can be passed either as fs.ReadStream or as file-like object containing file name, mime-type and its content.

        • Optionalparams?: string | { [key: string]: string | number | boolean } | URLSearchParams

          Query parameters to be sent with the URL.

        • Optionalsignal?: AbortSignal

          Allows to cancel the operation using an AbortSignal. If the signal is aborted, the operation will be aborted and throw an error. Note that providing a signal does not disable the default timeout, which can be changed using browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout); pass timeout: 0 to disable the timeout entirely.

        • Optionaltimeout?: number

          Request timeout in milliseconds. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.

      Returns Promise<APIResponse>

    • All responses returned by apiRequestContext.get(url[, options]) and similar methods are stored in the memory, so that you can later call apiResponse.body().This method discards all its resources, calling any method on disposed APIRequestContext will throw an exception.

      Parameters

      • Optionaloptions: { reason?: string }
        • Optionalreason?: string

          The reason to be reported to the operations interrupted by the context disposal.

      Returns Promise<void>

    • Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update context cookies from the response. The method will automatically follow redirects.

      Usage

      JSON objects can be passed directly to the request:

      await request.fetch('https://example.com/api/createBook', {
      method: 'post',
      data: {
      title: 'Book Title',
      author: 'John Doe',
      }
      });

      The common way to send file(s) in the body of a request is to upload them as form fields with multipart/form-data encoding, by specifiying the multipart parameter:

      const form = new FormData();
      form.set('name', 'John');
      form.append('name', 'Doe');
      // Send two file fields with the same name.
      form.append('file', new File(['console.log(2024);'], 'f1.js', { type: 'text/javascript' }));
      form.append('file', new File(['hello'], 'f2.txt', { type: 'text/plain' }));
      await request.fetch('https://example.com/api/uploadForm', {
      multipart: form
      });

      Parameters

      • urlOrRequest: string | Request

        Target URL or Request to get all parameters from.

      • Optionaloptions: {
            data?: any;
            failOnStatusCode?: boolean;
            form?: FormData | { [key: string]: string | number | boolean };
            headers?: { [key: string]: string };
            ignoreHTTPSErrors?: boolean;
            maxRedirects?: number;
            maxRetries?: number;
            method?: string;
            multipart?:
                | FormData
                | {
                    [key: string]: | string
                    | number
                    | boolean
                    | ReadStream
                    | { buffer: Buffer; mimeType: string; name: string };
                };
            params?: | string
            | URLSearchParams
            | { [key: string]: string
            | number
            | boolean };
            signal?: AbortSignal;
            timeout?: number;
        }
        • Optionaldata?: any

          Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and content-type header will be set to application/json if not explicitly set. Otherwise the content-type header will be set to application/octet-stream if not explicitly set.

        • OptionalfailOnStatusCode?: boolean

          Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.

        • Optionalform?: FormData | { [key: string]: string | number | boolean }

          Provides an object that will be serialized as html form using application/x-www-form-urlencoded encoding and sent as this request body. If this parameter is specified content-type header will be set to application/x-www-form-urlencoded unless explicitly provided.

        • Optionalheaders?: { [key: string]: string }

          Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by it.

        • OptionalignoreHTTPSErrors?: boolean

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

        • OptionalmaxRedirects?: number

          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.

        • OptionalmaxRetries?: number

          Maximum number of times network errors should be retried. Currently only ECONNRESET error is retried. Does not retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to 0 - no retries.

        • Optionalmethod?: string

          If set changes the fetch method (e.g. PUT or POST). If not specified, GET method is used.

        • Optionalmultipart?:
              | FormData
              | {
                  [key: string]: | string
                  | number
                  | boolean
                  | ReadStream
                  | { buffer: Buffer; mimeType: string; name: string };
              }

          Provides an object that will be serialized as html form using multipart/form-data encoding and sent as this request body. If this parameter is specified content-type header will be set to multipart/form-data unless explicitly provided. File values can be passed either as fs.ReadStream or as file-like object containing file name, mime-type and its content.

        • Optionalparams?: string | URLSearchParams | { [key: string]: string | number | boolean }

          Query parameters to be sent with the URL.

        • Optionalsignal?: AbortSignal

          Allows to cancel the operation using an AbortSignal. If the signal is aborted, the operation will be aborted and throw an error. Note that providing a signal does not disable the default timeout, which can be changed using browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout); pass timeout: 0 to disable the timeout entirely.

        • Optionaltimeout?: number

          Request timeout in milliseconds. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.

      Returns Promise<APIResponse>

    • Sends HTTP(S) GET request and returns its response. The method will populate request cookies from the context and update context cookies from the response. The method will automatically follow redirects.

      Usage

      Request parameters can be configured with params option, they will be serialized into the URL search parameters:

      // Passing params as object
      await request.get('https://example.com/api/getText', {
      params: {
      'isbn': '1234',
      'page': 23,
      }
      });

      // Passing params as URLSearchParams
      const searchParams = new URLSearchParams();
      searchParams.set('isbn', '1234');
      searchParams.append('page', 23);
      searchParams.append('page', 24);
      await request.get('https://example.com/api/getText', { params: searchParams });

      // Passing params as string
      const queryString = 'isbn=1234&page=23&page=24';
      await request.get('https://example.com/api/getText', { params: queryString });

      Parameters

      • url: string

        Target URL.

      • Optionaloptions: {
            data?: any;
            failOnStatusCode?: boolean;
            form?: FormData | { [key: string]: string | number | boolean };
            headers?: { [key: string]: string };
            ignoreHTTPSErrors?: boolean;
            maxRedirects?: number;
            maxRetries?: number;
            multipart?:
                | FormData
                | {
                    [key: string]: | string
                    | number
                    | boolean
                    | ReadStream
                    | { buffer: Buffer; mimeType: string; name: string };
                };
            params?: | string
            | URLSearchParams
            | { [key: string]: string
            | number
            | boolean };
            signal?: AbortSignal;
            timeout?: number;
        }
        • Optionaldata?: any

          Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and content-type header will be set to application/json if not explicitly set. Otherwise the content-type header will be set to application/octet-stream if not explicitly set.

        • OptionalfailOnStatusCode?: boolean

          Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.

        • Optionalform?: FormData | { [key: string]: string | number | boolean }

          Provides an object that will be serialized as html form using application/x-www-form-urlencoded encoding and sent as this request body. If this parameter is specified content-type header will be set to application/x-www-form-urlencoded unless explicitly provided.

        • Optionalheaders?: { [key: string]: string }

          Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by it.

        • OptionalignoreHTTPSErrors?: boolean

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

        • OptionalmaxRedirects?: number

          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.

        • OptionalmaxRetries?: number

          Maximum number of times network errors should be retried. Currently only ECONNRESET error is retried. Does not retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to 0 - no retries.

        • Optionalmultipart?:
              | FormData
              | {
                  [key: string]: | string
                  | number
                  | boolean
                  | ReadStream
                  | { buffer: Buffer; mimeType: string; name: string };
              }

          Provides an object that will be serialized as html form using multipart/form-data encoding and sent as this request body. If this parameter is specified content-type header will be set to multipart/form-data unless explicitly provided. File values can be passed either as fs.ReadStream or as file-like object containing file name, mime-type and its content.

        • Optionalparams?: string | URLSearchParams | { [key: string]: string | number | boolean }

          Query parameters to be sent with the URL.

        • Optionalsignal?: AbortSignal

          Allows to cancel the operation using an AbortSignal. If the signal is aborted, the operation will be aborted and throw an error. Note that providing a signal does not disable the default timeout, which can be changed using browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout); pass timeout: 0 to disable the timeout entirely.

        • Optionaltimeout?: number

          Request timeout in milliseconds. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.

      Returns Promise<APIResponse>

    • Sends HTTP(S) HEAD request and returns its response. The method will populate request cookies from the context and update context cookies from the response. The method will automatically follow redirects.

      Parameters

      • url: string

        Target URL.

      • Optionaloptions: {
            data?: any;
            failOnStatusCode?: boolean;
            form?: FormData | { [key: string]: string | number | boolean };
            headers?: { [key: string]: string };
            ignoreHTTPSErrors?: boolean;
            maxRedirects?: number;
            maxRetries?: number;
            multipart?:
                | FormData
                | {
                    [key: string]: | string
                    | number
                    | boolean
                    | ReadStream
                    | { buffer: Buffer; mimeType: string; name: string };
                };
            params?: | string
            | URLSearchParams
            | { [key: string]: string
            | number
            | boolean };
            signal?: AbortSignal;
            timeout?: number;
        }
        • Optionaldata?: any

          Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and content-type header will be set to application/json if not explicitly set. Otherwise the content-type header will be set to application/octet-stream if not explicitly set.

        • OptionalfailOnStatusCode?: boolean

          Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.

        • Optionalform?: FormData | { [key: string]: string | number | boolean }

          Provides an object that will be serialized as html form using application/x-www-form-urlencoded encoding and sent as this request body. If this parameter is specified content-type header will be set to application/x-www-form-urlencoded unless explicitly provided.

        • Optionalheaders?: { [key: string]: string }

          Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by it.

        • OptionalignoreHTTPSErrors?: boolean

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

        • OptionalmaxRedirects?: number

          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.

        • OptionalmaxRetries?: number

          Maximum number of times network errors should be retried. Currently only ECONNRESET error is retried. Does not retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to 0 - no retries.

        • Optionalmultipart?:
              | FormData
              | {
                  [key: string]: | string
                  | number
                  | boolean
                  | ReadStream
                  | { buffer: Buffer; mimeType: string; name: string };
              }

          Provides an object that will be serialized as html form using multipart/form-data encoding and sent as this request body. If this parameter is specified content-type header will be set to multipart/form-data unless explicitly provided. File values can be passed either as fs.ReadStream or as file-like object containing file name, mime-type and its content.

        • Optionalparams?: string | URLSearchParams | { [key: string]: string | number | boolean }

          Query parameters to be sent with the URL.

        • Optionalsignal?: AbortSignal

          Allows to cancel the operation using an AbortSignal. If the signal is aborted, the operation will be aborted and throw an error. Note that providing a signal does not disable the default timeout, which can be changed using browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout); pass timeout: 0 to disable the timeout entirely.

        • Optionaltimeout?: number

          Request timeout in milliseconds. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.

      Returns Promise<APIResponse>

    • Sends HTTP(S) PATCH request and returns its response. The method will populate request cookies from the context and update context cookies from the response. The method will automatically follow redirects.

      Parameters

      • url: string

        Target URL.

      • Optionaloptions: {
            data?: any;
            failOnStatusCode?: boolean;
            form?: FormData | { [key: string]: string | number | boolean };
            headers?: { [key: string]: string };
            ignoreHTTPSErrors?: boolean;
            maxRedirects?: number;
            maxRetries?: number;
            multipart?:
                | FormData
                | {
                    [key: string]: | string
                    | number
                    | boolean
                    | ReadStream
                    | { buffer: Buffer; mimeType: string; name: string };
                };
            params?: | string
            | URLSearchParams
            | { [key: string]: string
            | number
            | boolean };
            signal?: AbortSignal;
            timeout?: number;
        }
        • Optionaldata?: any

          Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and content-type header will be set to application/json if not explicitly set. Otherwise the content-type header will be set to application/octet-stream if not explicitly set.

        • OptionalfailOnStatusCode?: boolean

          Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.

        • Optionalform?: FormData | { [key: string]: string | number | boolean }

          Provides an object that will be serialized as html form using application/x-www-form-urlencoded encoding and sent as this request body. If this parameter is specified content-type header will be set to application/x-www-form-urlencoded unless explicitly provided.

        • Optionalheaders?: { [key: string]: string }

          Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by it.

        • OptionalignoreHTTPSErrors?: boolean

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

        • OptionalmaxRedirects?: number

          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.

        • OptionalmaxRetries?: number

          Maximum number of times network errors should be retried. Currently only ECONNRESET error is retried. Does not retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to 0 - no retries.

        • Optionalmultipart?:
              | FormData
              | {
                  [key: string]: | string
                  | number
                  | boolean
                  | ReadStream
                  | { buffer: Buffer; mimeType: string; name: string };
              }

          Provides an object that will be serialized as html form using multipart/form-data encoding and sent as this request body. If this parameter is specified content-type header will be set to multipart/form-data unless explicitly provided. File values can be passed either as fs.ReadStream or as file-like object containing file name, mime-type and its content.

        • Optionalparams?: string | URLSearchParams | { [key: string]: string | number | boolean }

          Query parameters to be sent with the URL.

        • Optionalsignal?: AbortSignal

          Allows to cancel the operation using an AbortSignal. If the signal is aborted, the operation will be aborted and throw an error. Note that providing a signal does not disable the default timeout, which can be changed using browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout); pass timeout: 0 to disable the timeout entirely.

        • Optionaltimeout?: number

          Request timeout in milliseconds. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.

      Returns Promise<APIResponse>

    post

    • post(
          url: string,
          options?: {
              data?: any;
              failOnStatusCode?: boolean;
              form?: FormData | { [key: string]: string | number | boolean };
              headers?: { [key: string]: string };
              ignoreHTTPSErrors?: boolean;
              maxRedirects?: number;
              maxRetries?: number;
              multipart?:
                  | FormData
                  | {
                      [key: string]: | string
                      | number
                      | boolean
                      | ReadStream
                      | { buffer: Buffer; mimeType: string; name: string };
                  };
              params?: | string
              | URLSearchParams
              | { [key: string]: string
              | number
              | boolean };
              signal?: AbortSignal;
              timeout?: number;
          },
      ): Promise<APIResponse>

      Sends HTTP(S) POST request and returns its response. The method will populate request cookies from the context and update context cookies from the response. The method will automatically follow redirects.

      Usage

      JSON objects can be passed directly to the request:

      await request.post('https://example.com/api/createBook', {
      data: {
      title: 'Book Title',
      author: 'John Doe',
      }
      });

      To send form data to the server use form option. Its value will be encoded into the request body with application/x-www-form-urlencoded encoding (see below how to use multipart/form-data form encoding to send files):

      await request.post('https://example.com/api/findBook', {
      form: {
      title: 'Book Title',
      author: 'John Doe',
      }
      });

      The common way to send file(s) in the body of a request is to upload them as form fields with multipart/form-data encoding. Use [FormData] to construct request body and pass it to the request as multipart parameter:

      const form = new FormData();
      form.set('name', 'John');
      form.append('name', 'Doe');
      // Send two file fields with the same name.
      form.append('file', new File(['console.log(2024);'], 'f1.js', { type: 'text/javascript' }));
      form.append('file', new File(['hello'], 'f2.txt', { type: 'text/plain' }));
      await request.post('https://example.com/api/uploadForm', {
      multipart: form
      });

      Parameters

      • url: string

        Target URL.

      • Optionaloptions: {
            data?: any;
            failOnStatusCode?: boolean;
            form?: FormData | { [key: string]: string | number | boolean };
            headers?: { [key: string]: string };
            ignoreHTTPSErrors?: boolean;
            maxRedirects?: number;
            maxRetries?: number;
            multipart?:
                | FormData
                | {
                    [key: string]: | string
                    | number
                    | boolean
                    | ReadStream
                    | { buffer: Buffer; mimeType: string; name: string };
                };
            params?: | string
            | URLSearchParams
            | { [key: string]: string
            | number
            | boolean };
            signal?: AbortSignal;
            timeout?: number;
        }
        • Optionaldata?: any

          Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and content-type header will be set to application/json if not explicitly set. Otherwise the content-type header will be set to application/octet-stream if not explicitly set.

        • OptionalfailOnStatusCode?: boolean

          Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.

        • Optionalform?: FormData | { [key: string]: string | number | boolean }

          Provides an object that will be serialized as html form using application/x-www-form-urlencoded encoding and sent as this request body. If this parameter is specified content-type header will be set to application/x-www-form-urlencoded unless explicitly provided.

        • Optionalheaders?: { [key: string]: string }

          Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by it.

        • OptionalignoreHTTPSErrors?: boolean

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

        • OptionalmaxRedirects?: number

          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.

        • OptionalmaxRetries?: number

          Maximum number of times network errors should be retried. Currently only ECONNRESET error is retried. Does not retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to 0 - no retries.

        • Optionalmultipart?:
              | FormData
              | {
                  [key: string]: | string
                  | number
                  | boolean
                  | ReadStream
                  | { buffer: Buffer; mimeType: string; name: string };
              }

          Provides an object that will be serialized as html form using multipart/form-data encoding and sent as this request body. If this parameter is specified content-type header will be set to multipart/form-data unless explicitly provided. File values can be passed either as fs.ReadStream or as file-like object containing file name, mime-type and its content.

        • Optionalparams?: string | URLSearchParams | { [key: string]: string | number | boolean }

          Query parameters to be sent with the URL.

        • Optionalsignal?: AbortSignal

          Allows to cancel the operation using an AbortSignal. If the signal is aborted, the operation will be aborted and throw an error. Note that providing a signal does not disable the default timeout, which can be changed using browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout); pass timeout: 0 to disable the timeout entirely.

        • Optionaltimeout?: number

          Request timeout in milliseconds. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.

      Returns Promise<APIResponse>

    • Sends HTTP(S) PUT request and returns its response. The method will populate request cookies from the context and update context cookies from the response. The method will automatically follow redirects.

      Parameters

      • url: string

        Target URL.

      • Optionaloptions: {
            data?: any;
            failOnStatusCode?: boolean;
            form?: FormData | { [key: string]: string | number | boolean };
            headers?: { [key: string]: string };
            ignoreHTTPSErrors?: boolean;
            maxRedirects?: number;
            maxRetries?: number;
            multipart?:
                | FormData
                | {
                    [key: string]: | string
                    | number
                    | boolean
                    | ReadStream
                    | { buffer: Buffer; mimeType: string; name: string };
                };
            params?: | string
            | URLSearchParams
            | { [key: string]: string
            | number
            | boolean };
            signal?: AbortSignal;
            timeout?: number;
        }
        • Optionaldata?: any

          Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and content-type header will be set to application/json if not explicitly set. Otherwise the content-type header will be set to application/octet-stream if not explicitly set.

        • OptionalfailOnStatusCode?: boolean

          Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.

        • Optionalform?: FormData | { [key: string]: string | number | boolean }

          Provides an object that will be serialized as html form using application/x-www-form-urlencoded encoding and sent as this request body. If this parameter is specified content-type header will be set to application/x-www-form-urlencoded unless explicitly provided.

        • Optionalheaders?: { [key: string]: string }

          Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by it.

        • OptionalignoreHTTPSErrors?: boolean

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

        • OptionalmaxRedirects?: number

          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.

        • OptionalmaxRetries?: number

          Maximum number of times network errors should be retried. Currently only ECONNRESET error is retried. Does not retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to 0 - no retries.

        • Optionalmultipart?:
              | FormData
              | {
                  [key: string]: | string
                  | number
                  | boolean
                  | ReadStream
                  | { buffer: Buffer; mimeType: string; name: string };
              }

          Provides an object that will be serialized as html form using multipart/form-data encoding and sent as this request body. If this parameter is specified content-type header will be set to multipart/form-data unless explicitly provided. File values can be passed either as fs.ReadStream or as file-like object containing file name, mime-type and its content.

        • Optionalparams?: string | URLSearchParams | { [key: string]: string | number | boolean }

          Query parameters to be sent with the URL.

        • Optionalsignal?: AbortSignal

          Allows to cancel the operation using an AbortSignal. If the signal is aborted, the operation will be aborted and throw an error. Note that providing a signal does not disable the default timeout, which can be changed using browserContext.setDefaultTimeout(timeout) or page.setDefaultTimeout(timeout); pass timeout: 0 to disable the timeout entirely.

        • Optionaltimeout?: number

          Request timeout in milliseconds. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.

      Returns Promise<APIResponse>

    • Returns storage state for this request context, contains current cookies and local storage snapshot if it was passed to the constructor.

      Parameters

      • Optionaloptions: { indexedDB?: boolean; path?: string }
        • OptionalindexedDB?: boolean

          Set to true to include IndexedDB in the storage state snapshot.

        • Optionalpath?: string

          The file path to save the storage state to. If path is a relative path, then it is resolved relative to current working directory. If no path is provided, storage state is still returned, but won't be saved to the disk.

      Returns Promise<
          {
              cookies: {
                  domain: string;
                  expires: number;
                  httpOnly: boolean;
                  name: string;
                  path: string;
                  sameSite: "None"
                  | "Strict"
                  | "Lax";
                  secure: boolean;
                  value: string;
              }[];
              origins: {
                  localStorage: { name: string; value: string }[];
                  origin: string;
              }[];
          },
      >