Warning! This documentation is heavily in Work-in-Progress and subject to changes.
Runtime APIs

The following APIs are the same as the Web APIS you already know. Additionally, we follow the WinterCG (opens in a new tab) conventions.

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):

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

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

Global objects

console

Similar to the the standard console object on the browser and on Node.js, expect 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 (opens in a new tab).


process

The only usage of process is to access environment variables via process.env.

Example:

export function handler(request: Request): Response {
  return new Response(`My secret is: ${process.env.SECRET}`);
}

navigator.userAgent

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


crypto

The standard crypto object.

crypto.randomUUID()

The standard randomUUID() method. See the documentation on MDN (opens in a new tab).

crypto.getRandomValues()

The standard getRandomValues() method. See the documentation on MDN (opens in a new tab).

crypto.subtle

The standard CryptoSubtle object. See the documentation on MDN (opens in a new tab).

The following table summarizes the supported algorithms on each method:

sign(), verify()encrypt(), decrypt()digest()deriveBits(), deriveKey()wrapKey(), unwrapKey()
HMAC
SHA-1
SHA-256
SHA-384
SHA-512
AES-GCM

TextEncoder

The standard TextEncoder object. See the documentation on MDN (opens in a new tab).

TextDecoder

The standard TextDecoder object. See the documentation on MDN (opens in a new tab).

AbortController

The standard AbortController object. See the documentation on MDN (opens in a new tab).

AbortSignal

The standard AbortSignal object. See the documentation on MDN (opens in a new tab).

Blob

The standard Blob object. See the documentation on MDN (opens in a new tab).

File

The standard File object. See the documentation on MDN (opens in a new tab).


Fetch

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

Request

The standard Request object. See the documentation on MDN (opens in a new tab).

Response

The standard Response object. See the documentation on MDN (opens in a new tab).

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 (opens in a new tab).

⚠️
This URL implementation only supports URLs with a scheme.

URLSearchParams

The standard URLSearchParams object. See the documentation on MDN (opens in a new tab).

Headers

The standard Headers object. See the documentation on MDN (opens in a new tab).


Streams

ReadableStream

The standard ReadableStream object. See the documentation on MDN (opens in a new tab).

ReadableStreamDefaultReader

The standard ReadableStreamDefaultReader object. See the documentation on MDN (opens in a new tab).

WritableStream

The standard WritableStream object. See the documentation on MDN (opens in a new tab).

WritableStreamDefaultWriter

The standard WritableStreamDefaultWriter object. See the documentation on MDN (opens in a new tab).

TransformStream

The standard TransformStream object. See the documentation on MDN (opens in a new tab).

Global methods

fetch()

The standard fetch method. See the documentation on MDN (opens in a new tab).

atob()

The standard atob method. See the documentation on MDN (opens in a new tab).

btoa()

The standard btoa method. See the documentation on MDN (opens in a new tab).