BlogsCloudflareCross-Runtime Socket API Standardization

Cross-Runtime Socket API Standardization

Cross-Runtime Socket API Standardization

3
posts
2022–2023

Cloudflare, in partnership with Vercel, Shopify, and core contributors to Node.js and Deno, has established the Web-interoperable Runtimes Community Group (WinterCG) under W3C. This group aims to standardize web APIs for non-browser JavaScript environments, ensuring code portability and consistency across runtimes like Cloudflare Workers, Node.js, and Deno. Key initiatives include defining a Minimum Common Web Platform API, developing specifications for Web Cryptography Streams to address limitations in streaming cryptographic operations, and creating a subset of the fetch() API tailored for server environments, acknowledging the differences from browser implementations regarding concepts like 'origin' and cookie stores. The group's work will be submitted to existing W3C/WHATWG work streams, with the potential to develop its own specifications if web browser needs are not met.

2023

A Socket API that works across JavaScript runtimes — announcing a WinterCG spec and Node.js implementation of connect()

9/28/2023

Published a draft specification for the connect() sockets API, designed for cross-runtime compatibility in JavaScript environments. Released a Node.js implementation of this API to facilitate adoption by library maintainers and application developers. The API is promise-based and leverages existing web standards like ReadableStream and WritableStream. It supports plain-text, TLS, and startTLS modes for secure connections. The goal is to eventually contribute this API as a built-in feature to Node.js.

Announcing connect() — a new API for creating TCP sockets from Cloudflare Workers

5/16/2023

Introduced the `connect()` API for creating outbound TCP sockets from Cloudflare Workers, enabling direct connections to any TCP-based service. This API aims for cross-runtime compatibility, drawing inspiration from existing standards and proposals. It supports opportunistic TLS via a `startTls()` method and aims to abstract TLS configuration to host infrastructure. The API is designed to allow immediate writing before TLS handshake completion and has been integrated into the `pg` PostgreSQL driver.

2022

A Community Group for Web-interoperable JavaScript runtimes

5/9/2022

This post announces the establishment of the Web-interoperable Runtimes Community Group (WinterCG) to standardize web APIs across non-browser JavaScript runtimes. It details the motivation for this group, focusing on developer portability and the need for consistent API implementations (e.g., fetch(), Streams, URL). It outlines the group's structure under W3C and its goals, emphasizing 'web-interoperable' as consistency with browser implementations. It also introduces initial work items: the Minimum Common Web Platform API (a curated subset of existing web APIs), Web Cryptography Streams for streaming crypto operations, and a server-specific subset of fetch() that accounts for differences from browser environments.