Class: Playwright::APIResponse

Inherits:
PlaywrightApi show all
Defined in:
lib/playwright_api/api_response.rb,
sig/playwright.rbs

Overview

APIResponse class represents responses returned by [method: APIRequestContext.get] and similar methods.

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    context = playwright.request.new_context()
    response = context.get("https://example.com/user/repos")
    assert response.ok
    assert response.status == 200
    assert response.headers["content-type"] == "application/json; charset=utf-8"
    assert response.json()["name"] == "foobar"
    assert response.body() == '{"status": "ok"}'

Instance Method Summary collapse

Methods inherited from PlaywrightApi

#initialize, unwrap, wrap

Constructor Details

This class inherits a constructor from Playwright::PlaywrightApi

Instance Method Details

#bodyString

Returns the buffer with response body.

Returns:

  • (String)


21
22
23
# File 'lib/playwright_api/api_response.rb', line 21

def body
  wrap_impl(@impl.body)
end

#disposevoid

This method returns an undefined value.

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



27
28
29
# File 'lib/playwright_api/api_response.rb', line 27

def dispose
  wrap_impl(@impl.dispose)
end

#headersHash[untyped, untyped]

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

Returns:

  • (Hash[untyped, untyped])


33
34
35
# File 'lib/playwright_api/api_response.rb', line 33

def headers
  wrap_impl(@impl.headers)
end

#headers_arrayArray[untyped]

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:

  • (Array[untyped])


40
41
42
# File 'lib/playwright_api/api_response.rb', line 40

def headers_array
  wrap_impl(@impl.headers_array)
end

#jsonObject

Returns the JSON representation of response body.

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

Returns:

  • (Object)


48
49
50
# File 'lib/playwright_api/api_response.rb', line 48

def json
  wrap_impl(@impl.json)
end

#okBoolean

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

Returns:

  • (Boolean)


54
55
56
# File 'lib/playwright_api/api_response.rb', line 54

def ok
  wrap_impl(@impl.ok)
end

#ok?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/playwright_api/api_response.rb', line 95

def ok?
  wrap_impl(@impl.ok?)
end

#security_detailsnil, Hash[untyped, untyped]

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

Returns:

  • (nil, Hash[untyped, untyped])


60
61
62
# File 'lib/playwright_api/api_response.rb', line 60

def security_details
  wrap_impl(@impl.security_details)
end

#server_addrnil, Hash[untyped, untyped]

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

Returns:

  • (nil, Hash[untyped, untyped])


66
67
68
# File 'lib/playwright_api/api_response.rb', line 66

def server_addr
  wrap_impl(@impl.server_addr)
end

#statusInteger

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

Returns:

  • (Integer)


72
73
74
# File 'lib/playwright_api/api_response.rb', line 72

def status
  wrap_impl(@impl.status)
end

#status_textString

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

Returns:

  • (String)


78
79
80
# File 'lib/playwright_api/api_response.rb', line 78

def status_text
  wrap_impl(@impl.status_text)
end

#textString

Returns the text representation of response body.

Returns:

  • (String)


84
85
86
# File 'lib/playwright_api/api_response.rb', line 84

def text
  wrap_impl(@impl.text)
end

#to_sObject



100
101
102
# File 'lib/playwright_api/api_response.rb', line 100

def to_s
  wrap_impl(@impl.to_s)
end

#urlString

Contains the URL of the response.

Returns:

  • (String)


90
91
92
# File 'lib/playwright_api/api_response.rb', line 90

def url
  wrap_impl(@impl.url)
end