Class: Playwright::APIResponse

Inherits:
PlaywrightApi show all
Defined in:
lib/playwright_api/api_response.rb

Overview

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

“‘python sync 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

#bodyObject

Returns the buffer with response body.



19
20
21
# File 'lib/playwright_api/api_response.rb', line 19

def body
  wrap_impl(@impl.body)
end

#disposeObject

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



24
25
26
# File 'lib/playwright_api/api_response.rb', line 24

def dispose
  wrap_impl(@impl.dispose)
end

#headersObject

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



29
30
31
# File 'lib/playwright_api/api_response.rb', line 29

def headers
  wrap_impl(@impl.headers)
end

#headers_arrayObject

An array with all the request 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.



35
36
37
# File 'lib/playwright_api/api_response.rb', line 35

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



42
43
44
# File 'lib/playwright_api/api_response.rb', line 42

def json
  wrap_impl(@impl.json)
end

#okObject

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



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

def ok
  wrap_impl(@impl.ok)
end

#ok?Boolean

Returns:

  • (Boolean)


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

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

#statusObject

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



52
53
54
# File 'lib/playwright_api/api_response.rb', line 52

def status
  wrap_impl(@impl.status)
end

#status_textObject

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



57
58
59
# File 'lib/playwright_api/api_response.rb', line 57

def status_text
  wrap_impl(@impl.status_text)
end

#textObject

Returns the text representation of response body.



62
63
64
# File 'lib/playwright_api/api_response.rb', line 62

def text
  wrap_impl(@impl.text)
end

#to_sObject



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

def to_s
  wrap_impl(@impl.to_s)
end

#urlObject

Contains the URL of the response.



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

def url
  wrap_impl(@impl.url)
end