Class: Playwright::APIResponse
- Inherits:
-
PlaywrightApi
- Object
- PlaywrightApi
- Playwright::APIResponse
- 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
-
#body ⇒ String
Returns the buffer with response body.
-
#dispose ⇒ void
Disposes the body of this response.
-
#headers ⇒ Hash[untyped, untyped]
An object with all the response HTTP headers associated with this response.
-
#headers_array ⇒ Array[untyped]
An array with all the response HTTP headers associated with this response.
-
#json ⇒ Object
Returns the JSON representation of response body.
-
#ok ⇒ Boolean
Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
- #ok? ⇒ Boolean
-
#security_details ⇒ nil, Hash[untyped, untyped]
Returns SSL and other security information.
-
#server_addr ⇒ nil, Hash[untyped, untyped]
Returns the IP address and port of the server.
-
#status ⇒ Integer
Contains the status code of the response (e.g., 200 for a success).
-
#status_text ⇒ String
Contains the status text of the response (e.g. usually an "OK" for a success).
-
#text ⇒ String
Returns the text representation of response body.
- #to_s ⇒ Object
-
#url ⇒ String
Contains the URL of the response.
Methods inherited from PlaywrightApi
Constructor Details
This class inherits a constructor from Playwright::PlaywrightApi
Instance Method Details
#body ⇒ String
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 |
#dispose ⇒ void
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 |
#headers ⇒ Hash[untyped, untyped]
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_array ⇒ Array[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.
40 41 42 |
# File 'lib/playwright_api/api_response.rb', line 40 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.
48 49 50 |
# File 'lib/playwright_api/api_response.rb', line 48 def json wrap_impl(@impl.json) end |
#ok ⇒ Boolean
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
95 96 97 |
# File 'lib/playwright_api/api_response.rb', line 95 def ok? wrap_impl(@impl.ok?) end |
#security_details ⇒ nil, 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.
60 61 62 |
# File 'lib/playwright_api/api_response.rb', line 60 def security_details wrap_impl(@impl.security_details) end |
#server_addr ⇒ nil, 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.
66 67 68 |
# File 'lib/playwright_api/api_response.rb', line 66 def server_addr wrap_impl(@impl.server_addr) end |
#status ⇒ Integer
Contains the status code of the response (e.g., 200 for a success).
72 73 74 |
# File 'lib/playwright_api/api_response.rb', line 72 def status wrap_impl(@impl.status) end |
#status_text ⇒ String
Contains the status text of the response (e.g. usually an "OK" for a success).
78 79 80 |
# File 'lib/playwright_api/api_response.rb', line 78 def status_text wrap_impl(@impl.status_text) end |
#text ⇒ String
Returns the text representation of response body.
84 85 86 |
# File 'lib/playwright_api/api_response.rb', line 84 def text wrap_impl(@impl.text) end |
#to_s ⇒ Object
100 101 102 |
# File 'lib/playwright_api/api_response.rb', line 100 def to_s wrap_impl(@impl.to_s) end |
#url ⇒ String
Contains the URL of the response.
90 91 92 |
# File 'lib/playwright_api/api_response.rb', line 90 def url wrap_impl(@impl.url) end |