API Reference

This section provides comprehensive documentation for all APIs available in Andromeda. The APIs are organized by category and follow web standards wherever possible.

Core APIs

Runtime APIs

File System APIs

Network APIs

Graphics APIs

Cryptography APIs

Web Standard APIs

Utility APIs

API Categories

Standard Web APIs

Andromeda implements many standard web APIs to provide compatibility with existing JavaScript/TypeScript code:

Runtime-Specific APIs

APIs that provide access to the underlying system and runtime environment:

Graphics and Media APIs

APIs for working with graphics and visual content:

API Design Principles

Web Standards Compliance

Andromeda APIs follow web standards wherever possible:

TypeScript Support

All APIs are designed with TypeScript in mind:

Cross-Platform Compatibility

APIs work consistently across different platforms:

Performance Focused

APIs are optimized for performance:

Common Patterns

Error Handling

Most APIs follow consistent error handling patterns:

try {
  const result = await someApiCall();
  // Handle success
} catch (error) {
  // Handle error
  console.error("API call failed:", error.message);
}

Async Operations

APIs that perform I/O operations are typically async:

// File operations
const content = await Deno.readTextFile("file.txt");

// Network operations
const response = await fetch("https://api.example.com/data");

Configuration Objects

Many APIs accept configuration objects for flexibility:

// Canvas context with options
const canvas = new OffscreenCanvas(800, 600);
const ctx = canvas.getContext("2d", {
  alpha: false,
  desynchronized: true,
});

// Text decoder with options
const decoder = new TextDecoder("utf-8", {
  fatal: true,
  ignoreBOM: false,
});

Getting Started

Basic API Usage

// Console output
console.log("Hello, Andromeda!");

// File operations
const content = await Deno.readTextFile("config.json");
const config = JSON.parse(content);

// HTTP requests
const response = await fetch("https://api.example.com/data");
const data = await response.json();

// Canvas graphics
const canvas = new OffscreenCanvas(400, 300);
const ctx = canvas.getContext("2d")!;
ctx.fillStyle = "blue";
ctx.fillRect(10, 10, 100, 100);

Working with Multiple APIs

import { performance } from "./performance.js";

async function processData() {
  const start = performance.now();

  try {
    // Read input file
    const input = await Deno.readTextFile("input.txt");

    // Process with crypto
    const encoder = new TextEncoder();
    const data = encoder.encode(input);
    const hash = await crypto.subtle.digest("SHA-256", data);

    // Log results
    console.log("Processing completed");
    console.log(
      "Hash:",
      Array.from(new Uint8Array(hash))
        .map((b) => b.toString(16).padStart(2, "0"))
        .join(""),
    );
  } catch (error) {
    console.error("Processing failed:", error);
  } finally {
    const duration = performance.now() - start;
    console.log(`Operation took ${duration.toFixed(2)}ms`);
  }
}

API Reference Organization

Each API documentation includes:

Contributing to API Documentation

If you find issues in the API documentation or want to contribute improvements:

  1. Check the existing documentation for accuracy
  2. Test examples to ensure they work correctly
  3. Submit issues or pull requests with improvements
  4. Follow the established documentation format and style

See Also