Skip to content

ext_net

The ext_net crate provides HTTP fetch and network operations for Forge applications through the host:net module.

Overview

ext_net handles:

  • HTTP fetch - GET, POST, PUT, DELETE, etc.
  • Request configuration - Headers, body, timeout
  • Response handling - JSON, text, bytes
  • Capability-based security - URL-based permission checks

Module: host:net

import {
fetchJson,
fetchText,
fetchBytes
} from "host:net";

Key Types

Error Types

enum NetErrorCode {
Io = 1000,
PermissionDenied = 1001,
InvalidUrl = 1002,
Timeout = 1003,
ConnectionFailed = 1004,
RequestFailed = 1005,
}
struct NetError {
code: NetErrorCode,
message: String,
}

Request/Response Types

struct FetchOpts {
method: Option<String>,
headers: Option<HashMap<String, String>>,
body: Option<String>,
timeout_ms: Option<u64>,
}
struct FetchResponse {
status: u16,
headers: HashMap<String, String>,
body: String,
}
struct FetchBytesResponse {
status: u16,
headers: HashMap<String, String>,
body: Vec<u8>,
}

Capability Types

struct NetCapabilities {
allowed_hosts: Vec<String>,
denied_hosts: Vec<String>,
}
trait NetCapabilityChecker {
fn check_url(&self, url: &str) -> bool;
}

Operations

OpTypeScriptDescription
op_net_fetchfetch(url, opts?)HTTP fetch returning text
op_net_fetch_jsonfetchJson(url, opts?)HTTP fetch parsing JSON
op_net_fetch_bytesfetchBytes(url, opts?)HTTP fetch returning bytes

File Structure

crates/ext_net/
├── src/
│ └── lib.rs # Extension implementation
├── ts/
│ └── init.ts # TypeScript module shim
├── build.rs # forge-weld build configuration
└── Cargo.toml

Dependencies

DependencyPurpose
deno_coreOp definitions
reqwestHTTP client
urlURL parsing
tokioAsync runtime
serdeJSON serialization
tracingLogging
forge-weldBuild-time code generation