pub struct APIRequest { /* private fields */ }Expand description
Factory for creating standalone APIRequestContext instances.
Obtained via playwright.request(). Use new_context() to create a context
for making HTTP requests outside of a browser page.
APIRequest intentionally holds only the channel and connection reference,
NOT a Playwright clone. Holding a Playwright clone would trigger the
server shutdown Drop impl when the temporary APIRequest is dropped.
§Example
ⓘ
use playwright_rs::protocol::Playwright;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let playwright = Playwright::launch().await?;
let ctx = playwright.request().new_context(None).await?;
let response = ctx.get("https://example.com/api/data", None).await?;
assert!(response.ok());
let body = response.text().await?;
ctx.dispose().await?;
playwright.shutdown().await?;
Ok(())
}Implementations§
Source§impl APIRequest
impl APIRequest
Sourcepub async fn new_context(
&self,
options: Option<APIRequestContextOptions>,
) -> Result<APIRequestContext>
pub async fn new_context( &self, options: Option<APIRequestContextOptions>, ) -> Result<APIRequestContext>
Creates a new APIRequestContext for making HTTP requests.
§Arguments
options— Optional configuration for the new context
See: https://playwright.dev/docs/api/class-apirequest#api-request-new-context
Trait Implementations§
Auto Trait Implementations§
impl Freeze for APIRequest
impl !RefUnwindSafe for APIRequest
impl Send for APIRequest
impl Sync for APIRequest
impl Unpin for APIRequest
impl UnsafeUnpin for APIRequest
impl !UnwindSafe for APIRequest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more