Class: Playwright::APIResponse
- Inherits:
-
PlaywrightApi
- Object
- PlaywrightApi
- Playwright::APIResponse
- 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
-
#body ⇒ Object
Returns the buffer with response body.
-
#dispose ⇒ Object
Disposes the body of this response.
-
#headers ⇒ Object
An object with all the response HTTP headers associated with this response.
-
#headers_array ⇒ Object
An array with all the request HTTP headers associated with this response.
-
#json ⇒ Object
Returns the JSON representation of response body.
-
#ok ⇒ Object
Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
- #ok? ⇒ Boolean
-
#status ⇒ Object
Contains the status code of the response (e.g., 200 for a success).
-
#status_text ⇒ Object
Contains the status text of the response (e.g. usually an “OK” for a success).
-
#text ⇒ Object
Returns the text representation of response body.
- #to_s ⇒ Object
-
#url ⇒ Object
Contains the URL of the response.
Methods inherited from PlaywrightApi
Constructor Details
This class inherits a constructor from Playwright::PlaywrightApi
Instance Method Details
#body ⇒ Object
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 |
#dispose ⇒ Object
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 |
#headers ⇒ Object
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_array ⇒ Object
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 |
#json ⇒ Object
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 |
#ok ⇒ Object
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
72 73 74 |
# File 'lib/playwright_api/api_response.rb', line 72 def ok? wrap_impl(@impl.ok?) end |
#status ⇒ Object
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_text ⇒ Object
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 |
#text ⇒ Object
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_s ⇒ Object
77 78 79 |
# File 'lib/playwright_api/api_response.rb', line 77 def to_s wrap_impl(@impl.to_s) end |
#url ⇒ Object
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 |