pub struct APIRequestContext { /* private fields */ }Expand description
APIRequestContext provides methods for making HTTP requests.
This is the Playwright protocol object that performs actual HTTP operations.
It is created automatically for each BrowserContext and can be accessed
via BrowserContext::request().
Used internally by Route::fetch() to perform the actual network request.
See: https://playwright.dev/docs/api/class-apirequestcontext
Implementations§
Source§impl APIRequestContext
impl APIRequestContext
pub fn new( parent: ParentOrConnection, type_name: String, guid: Arc<str>, initializer: Value, ) -> Result<Self>
Sourcepub async fn get(
&self,
url: &str,
options: impl Into<Option<FetchOptions>>,
) -> Result<APIResponse>
pub async fn get( &self, url: &str, options: impl Into<Option<FetchOptions>>, ) -> Result<APIResponse>
Sends a GET request.
See: https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-get
Sourcepub async fn post(
&self,
url: &str,
options: impl Into<Option<FetchOptions>>,
) -> Result<APIResponse>
pub async fn post( &self, url: &str, options: impl Into<Option<FetchOptions>>, ) -> Result<APIResponse>
Sends a POST request.
See: https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-post
Sourcepub async fn put(
&self,
url: &str,
options: impl Into<Option<FetchOptions>>,
) -> Result<APIResponse>
pub async fn put( &self, url: &str, options: impl Into<Option<FetchOptions>>, ) -> Result<APIResponse>
Sends a PUT request.
See: https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-put
Sourcepub async fn delete(
&self,
url: &str,
options: impl Into<Option<FetchOptions>>,
) -> Result<APIResponse>
pub async fn delete( &self, url: &str, options: impl Into<Option<FetchOptions>>, ) -> Result<APIResponse>
Sends a DELETE request.
See: https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-delete
Sourcepub async fn patch(
&self,
url: &str,
options: impl Into<Option<FetchOptions>>,
) -> Result<APIResponse>
pub async fn patch( &self, url: &str, options: impl Into<Option<FetchOptions>>, ) -> Result<APIResponse>
Sends a PATCH request.
See: https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-patch
Sourcepub async fn head(
&self,
url: &str,
options: impl Into<Option<FetchOptions>>,
) -> Result<APIResponse>
pub async fn head( &self, url: &str, options: impl Into<Option<FetchOptions>>, ) -> Result<APIResponse>
Sends a HEAD request.
See: https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-head
Sourcepub async fn fetch(
&self,
url: &str,
options: impl Into<Option<FetchOptions>>,
) -> Result<APIResponse>
pub async fn fetch( &self, url: &str, options: impl Into<Option<FetchOptions>>, ) -> Result<APIResponse>
Sends a fetch request with the given options, returning an APIResponse.
This is the public-facing fetch method that returns a lazy APIResponse.
The response body is not fetched until body(), text(), or json() is called.
See: https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-fetch
Adds cookies to this request context’s cookie jar. For the context
a BrowserContext or Page exposes through request(), that is the
browser context’s jar, so the cookies reach its pages too.
Each cookie needs a url, or a domain and path.
§Errors
Returns error if a cookie has neither a url nor a domain and
path, or the context has been disposed.
See: https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-add-cookies
Returns the cookies in this request context’s jar, filtered to those
that apply to urls when given.
§Errors
Returns error if the context has been disposed.
See: https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-cookies
Removes cookies from this request context’s jar: all of them, or those
matching every filter set in options.
§Errors
Returns error if the context has been disposed.
See: https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-clear-cookies
Sourcepub async fn dispose(&self) -> Result<()>
pub async fn dispose(&self) -> Result<()>
Disposes this APIRequestContext, freeing server resources.
After calling dispose(), the context cannot be used for further requests.
See: https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-dispose