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.



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

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.



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

def dispose
  wrap_impl(@impl.dispose)
end

#headersObject

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



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

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.



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



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

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.



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

def ok
  wrap_impl(@impl.ok)
end

#ok?Boolean

Returns:

  • (Boolean)


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

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

#statusObject

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



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

def status
  wrap_impl(@impl.status)
end

#status_textObject

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



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

def status_text
  wrap_impl(@impl.status_text)
end

#textObject

Returns the text representation of response body.



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

def text
  wrap_impl(@impl.text)
end

#to_sObject



88
89
90
# File 'lib/playwright_api/api_response.rb', line 88

def to_s
  wrap_impl(@impl.to_s)
end

#urlObject

Contains the URL of the response.



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

def url
  wrap_impl(@impl.url)
end