shape-runtime 0.3.1

Bytecode compiler, builtins, and runtime infrastructure for Shape
Documentation
/// @module std::core::http
/// HTTP Client
///
/// Make HTTP requests to web services. All functions are async and return
/// a Result containing an HttpResponse with status, headers, body, and ok fields.
///
/// # Example
///
/// ```shape
/// use std::core::http
///
/// let response = http.get("https://api.example.com/data", {})
/// match response {
///     Ok(r) => {
///         if r["ok"] { print(r["body"]) }
///         else { print(f"HTTP {r["status"]}") }
///     }
///     Err(e) => print(f"Request failed: {e}")
/// }
/// ```

/// Perform an HTTP GET request.
///
/// # Arguments
///
/// * `url` - URL to request
/// * `options` - Request options: `{ headers?: HashMap, timeout?: number }` (pass `{}` for defaults)
///
/// # Returns
///
/// `Ok({ status, headers, body, ok })` with the response, or `Err(message)` on failure.
///
/// # Example
///
/// ```shape
/// let r = http.get("https://api.example.com/users", {})
/// let r = http.get("https://api.example.com/users", { headers: { "Authorization": "Bearer token" } })
/// ```
pub builtin fn get(url: string, options: _) -> Result<_, string>;

/// Perform an HTTP POST request with a text body.
///
/// Sets `Content-Type: text/plain; charset=utf-8` automatically.
///
/// # Arguments
///
/// * `url` - URL to request
/// * `body` - Request body as a string (sent verbatim)
/// * `options` - Request options: `{ headers?: HashMap, timeout?: number }` (pass `{}` for defaults)
///
/// # Returns
///
/// `Ok({ status, headers, body, ok })` with the response, or `Err(message)` on failure.
///
/// # Example
///
/// ```shape
/// let r = http.post_text("https://api.example.com/notes", "hello", {})
/// ```
pub builtin fn post_text(url: string, body: string, options: _) -> Result<_, string>;

/// Perform an HTTP POST request with a binary body.
///
/// Sets `Content-Type: application/octet-stream` automatically.
///
/// # Arguments
///
/// * `url` - URL to request
/// * `body` - Request body as a byte array (`Array<int>`, each element 0..=255)
/// * `options` - Request options: `{ headers?: HashMap, timeout?: number }` (pass `{}` for defaults)
///
/// # Returns
///
/// `Ok({ status, headers, body, ok })` with the response, or `Err(message)` on failure.
///
/// # Example
///
/// ```shape
/// let r = http.post_bytes("https://api.example.com/upload", [0x48, 0x69], {})
/// ```
pub builtin fn post_bytes(url: string, body: Array<int>, options: _) -> Result<_, string>;

/// Perform an HTTP PUT request with a text body.
///
/// Sets `Content-Type: text/plain; charset=utf-8` automatically.
///
/// # Arguments
///
/// * `url` - URL to request
/// * `body` - Request body as a string (sent verbatim)
/// * `options` - Request options: `{ headers?: HashMap, timeout?: number }` (pass `{}` for defaults)
///
/// # Returns
///
/// `Ok({ status, headers, body, ok })` with the response, or `Err(message)` on failure.
///
/// # Example
///
/// ```shape
/// let r = http.put_text("https://api.example.com/notes/1", "hello", {})
/// ```
pub builtin fn put_text(url: string, body: string, options: _) -> Result<_, string>;

/// Perform an HTTP PUT request with a binary body.
///
/// Sets `Content-Type: application/octet-stream` automatically.
///
/// # Arguments
///
/// * `url` - URL to request
/// * `body` - Request body as a byte array (`Array<int>`, each element 0..=255)
/// * `options` - Request options: `{ headers?: HashMap, timeout?: number }` (pass `{}` for defaults)
///
/// # Returns
///
/// `Ok({ status, headers, body, ok })` with the response, or `Err(message)` on failure.
///
/// # Example
///
/// ```shape
/// let r = http.put_bytes("https://api.example.com/files/1", [0x48, 0x69], {})
/// ```
pub builtin fn put_bytes(url: string, body: Array<int>, options: _) -> Result<_, string>;

/// Perform an HTTP POST request with a JSON body.
///
/// Sets `Content-Type: application/json` automatically. The body object
/// is serialized to JSON via the universal `JsonValue` intermediate
/// (N7 ε disposition; see `docs/defections.md`).
///
/// # Arguments
///
/// * `url` - URL to request
/// * `body` - Request body as an object (serialized to JSON)
/// * `options` - Request options: `{ headers?: HashMap, timeout?: number }` (pass `{}` for defaults)
///
/// # Returns
///
/// `Ok({ status, headers, body, ok })` with the response, or `Err(message)` on failure.
///
/// # Example
///
/// ```shape
/// let r = http.post_json("https://api.example.com/users", { name: "Alice", age: 30 }, {})
/// ```
pub builtin fn post_json(url: string, body: _, options: _) -> Result<_, string>;

/// Perform an HTTP PUT request with a JSON body.
///
/// Sets `Content-Type: application/json` automatically. Body serialization
/// matches `post_json`.
///
/// # Arguments
///
/// * `url` - URL to request
/// * `body` - Request body as an object (serialized to JSON)
/// * `options` - Request options: `{ headers?: HashMap, timeout?: number }` (pass `{}` for defaults)
///
/// # Returns
///
/// `Ok({ status, headers, body, ok })` with the response, or `Err(message)` on failure.
///
/// # Example
///
/// ```shape
/// let r = http.put_json("https://api.example.com/users/1", { name: "Alice" }, {})
/// ```
pub builtin fn put_json(url: string, body: _, options: _) -> Result<_, string>;

/// Perform an HTTP DELETE request.
///
/// # Arguments
///
/// * `url` - URL to request
/// * `options` - Request options: `{ headers?: HashMap, timeout?: number }` (pass `{}` for defaults)
///
/// # Returns
///
/// `Ok({ status, headers, body, ok })` with the response, or `Err(message)` on failure.
///
/// # Example
///
/// ```shape
/// let r = http.delete("https://api.example.com/users/1", {})
/// ```
pub builtin fn delete(url: string, options: _) -> Result<_, string>;