Skip to main content

APIRequestContext

Struct APIRequestContext 

Source
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

Source

pub fn new( parent: ParentOrConnection, type_name: String, guid: Arc<str>, initializer: Value, ) -> Result<Self>

Source

pub async fn get( &self, url: &str, options: impl Into<Option<FetchOptions>>, ) -> Result<APIResponse>

Source

pub async fn post( &self, url: &str, options: impl Into<Option<FetchOptions>>, ) -> Result<APIResponse>

Source

pub async fn put( &self, url: &str, options: impl Into<Option<FetchOptions>>, ) -> Result<APIResponse>

Source

pub async fn delete( &self, url: &str, options: impl Into<Option<FetchOptions>>, ) -> Result<APIResponse>

Source

pub async fn patch( &self, url: &str, options: impl Into<Option<FetchOptions>>, ) -> Result<APIResponse>

Source

pub async fn head( &self, url: &str, options: impl Into<Option<FetchOptions>>, ) -> Result<APIResponse>

Source

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

Source

pub async fn add_cookies(&self, cookies: &[Cookie]) -> Result<()>

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

Source

pub async fn cookies(&self, urls: Option<&[&str]>) -> Result<Vec<Cookie>>

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

Source

pub async fn clear_cookies( &self, options: impl Into<Option<ClearCookiesOptions>>, ) -> Result<()>

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

Source

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

Trait Implementations§

Source§

impl Clone for APIRequestContext

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for APIRequestContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more