quickstart
serverless-functions

Quick Start

Three steps: deploy, invoke, done.

1. Deploy a function

curl -X POST http://localhost:24006/deploy \
  -H "Content-Type: application/json" \
  -d '{
    "id": "hello",
    "code": "function handler(data) { return { message: \"Hello, \" + data.name + \"!\" }; }"
  }'
{ "id": "hello", "url": "/invoke/hello" }

2. Invoke it

curl -X POST http://localhost:24006/invoke/hello \
  -H "Content-Type: application/json" \
  -d '{"name": "World"}'
{ "message": "Hello, World!" }

3. That's it

Your function is live. Invoke it as many times as you want — each call takes ~1-5ms.

More examples

Async function with fetch

curl -X POST http://localhost:24006/deploy \
  -H "Content-Type: application/json" \
  -d '{
    "id": "github-user",
    "code": "async function handler(username) { const r = await fetch(\"https://api.github.com/users/\" + username); const d = await r.json(); return { name: d.name, repos: d.public_repos }; }"
  }'

curl -X POST http://localhost:24006/invoke/github-user \
  -H "Content-Type: application/json" \
  -d '"denoland"'
{ "name": "Deno Land Inc.", "repos": 142 }

Calculator

curl -X POST http://localhost:24006/deploy \
  -H "Content-Type: application/json" \
  -d '{
    "id": "calc",
    "code": "function handler({op, a, b}) { switch(op) { case \"add\": return a+b; case \"mul\": return a*b; default: throw new Error(\"unknown\"); } }"
  }'

curl -X POST http://localhost:24006/invoke/calc \
  -H "Content-Type: application/json" \
  -d '{"op":"add","a":42,"b":58}'
100

Managing functions

# List all functions
curl http://localhost:24006/scripts

# Delete a function
curl -X DELETE http://localhost:24006/delete/hello

# Server stats
curl http://localhost:24006/stats

Next