Skip to main content
Workerd provides a comprehensive set of runtime APIs that implement web standards and extend them with additional functionality for building serverless applications.

Web standard APIs

Workerd implements the following web standards:

Fetch API

The Fetch API provides interfaces for making HTTP requests and handling responses. It includes Request, Response, Headers, and the global fetch() function.
const response = await fetch('https://example.com');
const data = await response.json();

Streams API

The Streams API enables efficient processing of data streams. Workerd provides both standard WHATWG streams and optimized internal byte streams.
const stream = new ReadableStream({
  start(controller) {
    controller.enqueue('Hello ');
    controller.enqueue('World');
    controller.close();
  }
});

WebSocket API

The WebSocket API enables real-time bidirectional communication between clients and servers.
const pair = new WebSocketPair();
pair[1].accept();
pair[1].send('Connected');

Cache API

The Cache API provides programmatic control over HTTP caching.
const cache = caches.default;
await cache.put(request, response);
const cached = await cache.match(request);

Crypto API

The Crypto API implements the Web Crypto standard for cryptographic operations.
const hash = await crypto.subtle.digest(
  'SHA-256',
  new TextEncoder().encode('data')
);

Encoding APIs

The Encoding APIs provide text encoding and decoding functionality.
const encoder = new TextEncoder();
const bytes = encoder.encode('Hello World');

const decoder = new TextDecoder();
const text = decoder.decode(bytes);

Storage APIs

Workerd extends web standards with storage APIs:

KV storage

KV storage provides a key-value store for your applications.
await env.MY_KV.put('key', 'value');
const value = await env.MY_KV.get('key');

Durable Objects

Durable Objects provide strongly consistent, coordinated state.
export class Counter {
  constructor(state, env) {
    this.state = state;
  }

  async fetch(request) {
    let count = (await this.state.storage.get('count')) || 0;
    await this.state.storage.put('count', ++count);
    return new Response(count);
  }
}

R2 storage

R2 storage provides object storage with an S3-compatible API.
await env.MY_BUCKET.put('file.txt', 'contents');
const object = await env.MY_BUCKET.get('file.txt');
const text = await object.text();

Architecture

Workerd’s runtime APIs are implemented in C++ with JavaScript bindings through the JSG (JavaScript Glue) layer. This architecture provides:
  • Performance: Native C++ implementations for critical operations
  • Compatibility: Adherence to web standards where applicable
  • Extensions: Additional APIs beyond web standards for serverless use cases
  • Type safety: TypeScript definitions generated from C++ implementations

API organization

The runtime APIs are organized in the source code under src/workerd/api/:
  • http.h / http.c++ - Fetch API (Request, Response, fetch)
  • streams/ - Streams API implementations
  • web-socket.h / web-socket.c++ - WebSocket API
  • cache.h / cache.c++ - Cache API
  • kv.h / kv.c++ - KV storage API
  • actor-state.h / actor-state.c++ - Durable Objects storage
  • r2-bucket.h / r2-bucket.c++ - R2 storage API
  • crypto/ - Web Crypto API implementations
  • encoding.h / encoding.c++ - Text encoding APIs

Next steps

Fetch API

Learn about HTTP requests and responses

Streams API

Process data efficiently with streams

Durable Objects

Build stateful applications

R2 storage

Store and retrieve objects

Build docs developers (and LLMs) love