Skip to content

Runtime APIs

The following APIs are the same as the native Web APIS you already know. We also follow the WinterCG conventions. Lagoss's Runtime uses the V8 engine and is written in both Rust and TypeScript.

Handler

The only required code to make your Function runnable is to export a handler function, that accepts a Request and returns a Response (or a promise returning a Response):

typescript
export function handler(request: Request) {
  return new Response('Hello World!');
}

Starting from this simple code, you can do whatever you wish, using the Web APIs you already know.

Additional Headers

The Request object coming from the handler function also contains additional headers:

  • X-Lagoss-Region: the region where this Function is executing
  • X-Forwarded-For: the IP address of the client that made the request

You can access them the same as any other header:

typescript
export function handler(request: Request) {
  const region = request.headers.get('x-lagoss-region');
  const ip = request.headers.get('x-forwarded-for');

  return new Response(`Region: ${region}, User IP: ${ip}`);
}

The X-Lagoss-Region header is also automatically added to each response, making it easy to identify which Region served the request.

INFO

When developing locally using lagoss dev, the X-Lagoss-Region header will be set to local.

NPM support

Lagoss's Runtime supports any NPM package. The only requirement is that the package must not use Node.js-specific APIs (e.g Buffer, fs, path, etc.). This is because Lagoss's Runtime is not Node.js, but a browser-like environment.

Global objects

AbortController

The standard AbortController object. See the documentation on MDN.

AbortSignal

The standard AbortSignal object. See the documentation on MDN.

AsyncContext

An early implementation of the Async Context proposal. You shouldn't use this API yet, as it is still experimental and subject to change.

AsyncLocalStorage

A minimal implementation of Node.js's AsyncLocalStorage. The following methods are supported:

  • getStore()
  • run(store, callback, ...args)

Blob

The standard Blob object. See the documentation on MDN.

Compression Stream APIs

Lagoss supports all three compression formats: gzip, deflate and deflate-raw.

CompressionStream

The standard CompressionStream object. See the documentation on MDN.

DecompressionStream

The standard DecompressionStream object. See the documentation on MDN.

console

Similar to the standard console object on the browser and Node.js, except that it only supports the following methods:

  • log
  • info
  • debug
  • warn
  • error

You can log multiple objects, and use string substitution. See the documentation on MDN. See the Logs documentation to learn more.

crypto

The standard crypto object.

crypto.randomUUID()

The standard randomUUID() method. See the documentation on MDN.

crypto.getRandomValues()

The standard getRandomValues() method. See the documentation on MDN.

crypto.subtle

The standard CryptoSubtle object. See the documentation on MDN.

INFO

The following table summarizes the supported algorithms on each method:

sign(), verify()encrypt(), decrypt()digest()deriveBits(), deriveKey()wrapKey(), unwrapKey()
RSASSA-PKCS1-v1_5
RSA-PSS
ECDSA
HMAC
RSA-OAEP
AES-CTR
AES-CBC
AES-GCM
SHA-1
SHA-256
SHA-384
SHA-512
ECDH
HKDF
PBKDF2
AES-KW

CustomEvent

The standard CustomEvent object. See the documentation on MDN.

Event

The standard Event object. See the documentation on MDN.

EventTarget

The standard EventTarget object. See the documentation on MDN.

Fetch APIs

INFO

Looking for the fetch() method? Jump to fetch().

Headers

The standard Headers object. It also supports the getSetCookie() method. See the documentation on MDN.

Request

The standard Request object. See the documentation on MDN.

Response

The standard Response object. See the documentation on MDN.

Streaming: You can pass a ReadableStream object as the body of a Response to stream the response as more data becomes available. Often, you won't need to implement the logic yourself as it is implemented by the frameworks and libraries you use.

URL

The standard URL object. See the documentation on MDN.

WARNING

This URL implementation only supports URLs with a scheme.

URLSearchParams

The standard URLSearchParams object. See the documentation on MDN.

File

The standard File object. See the documentation on MDN.

FileReader

The standard FileReader object. See the documentation on MDN.

FormData

The standard FormData object. See the documentation on MDN.

navigator.userAgent is a fixed string that can be used to detect the current runtime. Its value is always Lagoss/VERSION, where VERSION is the current version of the Lagoss Runtime.

process.env

The only usage of process is to access environment variables. By default, it will only contain the NODE_ENV variable, which is set to "production" when deployed, and to "development" when using lagoss dev.

Learn more about environment variables.

ProgressEvent

The standard ProgressEvent object. See the documentation on MDN.

Stream APIs

ReadableStream

The standard ReadableStream object. See the documentation on MDN.

ReadableStreamDefaultReader

The standard ReadableStreamDefaultReader object. See the documentation on MDN.

TransformStream

The standard TransformStream object. See the documentation on MDN.

WritableStream

The standard WritableStream object. See the documentation on MDN.

WritableStreamDefaultWriter

The standard WritableStreamDefaultWriter object. See the documentation on MDN.

TextEncoder

The standard TextEncoder object. See the documentation on MDN.

TextDecoder

The standard TextDecoder object. See the documentation on MDN.

Global methods

atob()

The standard atob method. See the documentation on MDN.

btoa()

The standard btoa method. See the documentation on MDN.

clearInterval()

The standard clearInterval method. See the documentation on MDN.

clearTimeout()

The standard clearTimeout method. See the documentation on MDN.

fetch()

The standard fetch method. See the documentation on MDN.

INFO

fetch() supports both HTTP/1.1 and HTTP/2. Additionally, there are some limits in place to prevent abuses.

queueMicrotask()

The standard queueMicrotask method. See the documentation on MDN.

setInterval()

The standard setInterval method. See the documentation on MDN.

setTimeout()

The standard setTimeout method. See the documentation on MDN.