Playwright.APIResponse (Playwright v1.65.0-rc.3)

Copy Markdown View Source

APIResponse class represents responses returned by Playwright.APIRequestContext.get/3 and similar methods.

Since Playwright 1.16.

The examples alias the modules they use (alias Playwright.{Locator, Page}).

Summary

Types

t()

A APIResponse handle. Compare handles with ==, their fields are internal.

Functions

Returns the buffer with response body.

Like body/1, but returns the value and raises on error.

Disposes the body of this response. If not called then the body will stay in memory until the context closes.

Like dispose/1, but returns the value and raises on error.

An object with all the response HTTP headers associated with this response.

An array with all the response HTTP headers associated with this response. Header names are not lower-cased. Headers with multiple entries, such as Set-Cookie, appear in the array multiple times.

Returns the JSON representation of response body.

Like json/1, but returns the value and raises on error.

Contains a boolean stating whether the response was successful (status in the range 200-299) or not.

Returns SSL and other security information. Returns nil for non-HTTPS responses. For redirected requests, returns the information for the last request in the redirect chain.

Like security_details/1, but returns the value and raises on error.

Returns the IP address and port of the server. Returns nil if the server address is not available. For redirected requests, returns the information for the last request in the redirect chain.

Like server_addr/1, but returns the value and raises on error.

Contains the status code of the response (e.g., 200 for a success).

Contains the status text of the response (e.g. usually an "OK" for a success).

Returns the text representation of response body.

Like text/1, but returns the value and raises on error.

Returns resource timing information for given response. For redirected requests, returns the information for the last request in the redirect chain. When the response is served from the HAR file, timing information is not available and all the values are -1. Find more information at Resource Timing API.

Contains the URL of the response.

Types

t()

@type t() :: %Playwright.APIResponse{
  _apiName: term(),
  _headers: term(),
  _initializer: term(),
  _request: term()
}

A APIResponse handle. Compare handles with ==, their fields are internal.

Functions

body(api_response)

@spec body(t()) :: {:ok, binary()} | {:error, Playwright.error()}

Returns the buffer with response body.

Since Playwright 1.16.

body!(api_response)

@spec body!(t()) :: binary()

Like body/1, but returns the value and raises on error.

dispose(api_response)

@spec dispose(t()) :: :ok | {:error, Playwright.error()}

Disposes the body of this response. If not called then the body will stay in memory until the context closes.

Since Playwright 1.16.

dispose!(api_response)

@spec dispose!(t()) :: :ok

Like dispose/1, but returns the value and raises on error.

headers(api_response)

@spec headers(t()) :: %{optional(String.t()) => String.t()}

An object with all the response HTTP headers associated with this response.

Since Playwright 1.16.

headers_array(api_response)

@spec headers_array(t()) :: [%{name: String.t(), value: String.t()}]

An array with all the response HTTP headers associated with this response. Header names are not lower-cased. Headers with multiple entries, such as Set-Cookie, appear in the array multiple times.

Since Playwright 1.16.

json(api_response)

@spec json(t()) :: {:ok, term()} | {:error, Playwright.error()}

Returns the JSON representation of response body.

This method will fail if the response body is not parsable via JSON.parse.

Since Playwright 1.16.

json!(api_response)

@spec json!(t()) :: term()

Like json/1, but returns the value and raises on error.

ok(api_response)

@spec ok(t()) :: boolean()

Contains a boolean stating whether the response was successful (status in the range 200-299) or not.

Since Playwright 1.16.

security_details(api_response)

@spec security_details(t()) ::
  {:ok,
   nil
   | %{
       optional(:issuer) => String.t(),
       optional(:protocol) => String.t(),
       optional(:subjectName) => String.t(),
       optional(:validFrom) => number(),
       optional(:validTo) => number()
     }}
  | {:error, Playwright.error()}

Returns SSL and other security information. Returns nil for non-HTTPS responses. For redirected requests, returns the information for the last request in the redirect chain.

Since Playwright 1.61.

security_details!(api_response)

@spec security_details!(t()) ::
  nil
  | %{
      optional(:issuer) => String.t(),
      optional(:protocol) => String.t(),
      optional(:subjectName) => String.t(),
      optional(:validFrom) => number(),
      optional(:validTo) => number()
    }

Like security_details/1, but returns the value and raises on error.

server_addr(api_response)

@spec server_addr(t()) ::
  {:ok, nil | %{ipAddress: String.t(), port: integer()}}
  | {:error, Playwright.error()}

Returns the IP address and port of the server. Returns nil if the server address is not available. For redirected requests, returns the information for the last request in the redirect chain.

Since Playwright 1.61.

server_addr!(api_response)

@spec server_addr!(t()) :: nil | %{ipAddress: String.t(), port: integer()}

Like server_addr/1, but returns the value and raises on error.

status(api_response)

@spec status(t()) :: integer()

Contains the status code of the response (e.g., 200 for a success).

Since Playwright 1.16.

status_text(api_response)

@spec status_text(t()) :: String.t()

Contains the status text of the response (e.g. usually an "OK" for a success).

Since Playwright 1.16.

text(api_response)

@spec text(t()) :: {:ok, String.t()} | {:error, Playwright.error()}

Returns the text representation of response body.

Since Playwright 1.16.

text!(api_response)

@spec text!(t()) :: String.t()

Like text/1, but returns the value and raises on error.

timing(api_response)

@spec timing(t()) :: %{
  startTime: number(),
  domainLookupStart: number(),
  domainLookupEnd: number(),
  connectStart: number(),
  secureConnectionStart: number(),
  connectEnd: number(),
  requestStart: number(),
  responseStart: number(),
  responseEnd: number()
}

Returns resource timing information for given response. For redirected requests, returns the information for the last request in the redirect chain. When the response is served from the HAR file, timing information is not available and all the values are -1. Find more information at Resource Timing API.

Since Playwright 1.62.

url(api_response)

@spec url(t()) :: String.t()

Contains the URL of the response.

Since Playwright 1.16.