Skip to content
cloudhost
Functions

Code that runs on request.

Write a fetch handler and deploy it. It runs on every request, sleeps when idle, and is billed per request and active CPU time.

Web standards, not a private API

A function is a module with a fetch handler, the standard WinterTC shape. Request, Response, fetch, crypto and streams are the ones you know from the browser, and Node built-ins are available too.

export default {
  async fetch(request: Request, env: Env) {
    const url = new URL(request.url)
    return Response.json({ hello: url.searchParams.get("name") ?? "salam" })
  },
}

What you get

A nightly job, no server

Every day at 3 a.m. Tehran time, old carts are cleared. The database is awake for those few seconds only.

name = "reports"
type = "function"
main = "index.ts"

[[db]]
binding = "DB"
database = "shop"

[triggers]
crons = ["0 3 * * *"]

Functions that work together

One function calls another on the same edge and hands slow work to a queue. No address, no key.

name = "api"
type = "function"
main = "index.ts"

[[services]]
binding = "AUTH"
service = "auth"

[[queue]]
binding = "JOBS"
name = "jobs"

Per request and active CPU

Each run counts as one request, plus the time your code actually spent on the CPU. Waiting for a database or an outside API does not count. It comes out of the month's credit first.

Questions

Deploy your first function

One file, one command, one address.

Sign-up is by invite for now. If you have a code, create your account.

Sign up withEmail codeSMS code