Module api

Module api 

Source
Expand description

API testing support for making HTTP requests outside of browser context.

This module provides APIRequestContext for making HTTP requests directly, without needing a browser. This is useful for:

  • Setting up test data via API
  • Verifying backend state after UI actions
  • Getting authentication tokens
  • Running API-only tests without browser overhead

§Example

use viewpoint_core::api::{APIRequestContext, APIContextOptions};

// Create a standalone API context
let api = APIRequestContext::new(
    APIContextOptions::new()
        .base_url("https://api.example.com")
).await?;

// Make a GET request
let response = api.get("/users").send().await?;
assert!(response.ok());

// Make a POST request with JSON body
let user = serde_json::json!({ "name": "John", "email": "john@example.com" });
let response = api.post("/users")
    .json(&user)
    .send()
    .await?;

// Parse JSON response
let created_user: serde_json::Value = response.json().await?;

Modules§

cookies
Cookie synchronization between browser and API contexts.

Structs§

APIContextOptions
Options for creating an API request context.
APIRequestBuilder
Builder for constructing and sending HTTP requests.
APIRequestContext
Context for making API requests.
APIResponse
Response from an API request.
HttpCredentials
HTTP authentication credentials.
MultipartField
A field in a multipart form.
ProxyConfig
Proxy configuration.

Enums§

APIError
Errors that can occur during API operations.
CredentialSend
When to send credentials.
HttpMethod
HTTP method for API requests.