Skip to main content
Version: 1.17

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. When used on Page or a BrowserContext, this API will automatically use the cookies from the corresponding BrowserContext. This means that if you log in using this API, your e2e test will be logged in and vice versa.

apiRequestContext.delete(url[, options])

  • url <string> Target URL.#
  • options <Object>
    • data <string|Buffer|Serializable> 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.#
    • failOnStatusCode <boolean> Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.#
    • form <Object<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.#
    • headers <Object<string, string>> Allows to set HTTP headers.#
    • ignoreHTTPSErrors <boolean> Whether to ignore HTTPS errors when sending network requests. Defaults to false.#
    • multipart <Object<string, string|number|boolean|[ReadStream]|Object>> 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.#
    • params <Object<string, string|number|boolean>> Query parameters to be sent with the URL.#
    • timeout <number> Request timeout in milliseconds. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.#
  • returns: <Promise<APIResponse>>#

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.

apiRequestContext.dispose()

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 stored responses, and makes apiResponse.body() throw "Response disposed" error.

apiRequestContext.fetch(urlOrRequest[, options])

  • urlOrRequest <string|Request> Target URL or Request to get all parameters from.#
  • options <Object>
    • data <string|Buffer|Serializable> 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.#
    • failOnStatusCode <boolean> Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.#
    • form <Object<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.#
    • headers <Object<string, string>> Allows to set HTTP headers.#
    • ignoreHTTPSErrors <boolean> Whether to ignore HTTPS errors when sending network requests. Defaults to false.#
    • method <string> If set changes the fetch method (e.g. PUT or POST). If not specified, GET method is used.#
    • multipart <Object<string, string|number|boolean|[ReadStream]|Object>> 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.#
    • params <Object<string, string|number|boolean>> Query parameters to be sent with the URL.#
    • timeout <number> Request timeout in milliseconds. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.#
  • returns: <Promise<APIResponse>>#

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.

apiRequestContext.get(url[, options])

  • url <string> Target URL.#
  • options <Object>
    • failOnStatusCode <boolean> Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.#
    • headers <Object<string, string>> Allows to set HTTP headers.#
    • ignoreHTTPSErrors <boolean> Whether to ignore HTTPS errors when sending network requests. Defaults to false.#
    • params <Object<string, string|number|boolean>> Query parameters to be sent with the URL.#
    • timeout <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.

apiRequestContext.head(url[, options])

  • url <string> Target URL.#
  • options <Object>
    • failOnStatusCode <boolean> Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.#
    • headers <Object<string, string>> Allows to set HTTP headers.#
    • ignoreHTTPSErrors <boolean> Whether to ignore HTTPS errors when sending network requests. Defaults to false.#
    • params <Object<string, string|number|boolean>> Query parameters to be sent with the URL.#
    • timeout <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.

apiRequestContext.patch(url[, options])

  • url <string> Target URL.#
  • options <Object>
    • data <string|Buffer|Serializable> 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.#
    • failOnStatusCode <boolean> Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.#
    • form <Object<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.#
    • headers <Object<string, string>> Allows to set HTTP headers.#
    • ignoreHTTPSErrors <boolean> Whether to ignore HTTPS errors when sending network requests. Defaults to false.#
    • multipart <Object<string, string|number|boolean|[ReadStream]|Object>> 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.#
    • params <Object<string, string|number|boolean>> Query parameters to be sent with the URL.#
    • timeout <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.

apiRequestContext.post(url[, options])

  • url <string> Target URL.#
  • options <Object>
    • data <string|Buffer|Serializable> 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.#
    • failOnStatusCode <boolean> Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.#
    • form <Object<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.#
    • headers <Object<string, string>> Allows to set HTTP headers.#
    • ignoreHTTPSErrors <boolean> Whether to ignore HTTPS errors when sending network requests. Defaults to false.#
    • multipart <Object<string, string|number|boolean|[ReadStream]|Object>> 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.#
    • params <Object<string, string|number|boolean>> Query parameters to be sent with the URL.#
    • timeout <number> Request timeout in milliseconds. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.#
  • returns: <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.

apiRequestContext.put(url[, options])

  • url <string> Target URL.#
  • options <Object>
    • data <string|Buffer|Serializable> 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.#
    • failOnStatusCode <boolean> Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.#
    • form <Object<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.#
    • headers <Object<string, string>> Allows to set HTTP headers.#
    • ignoreHTTPSErrors <boolean> Whether to ignore HTTPS errors when sending network requests. Defaults to false.#
    • multipart <Object<string, string|number|boolean|[ReadStream]|Object>> 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.#
    • params <Object<string, string|number|boolean>> Query parameters to be sent with the URL.#
    • timeout <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.

apiRequestContext.storageState([options])

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