DEV Community

Alex Spinov
Alex Spinov

Posted on

Val Town Has a Free API That Lets You Run Code in the Cloud With Zero Setup

Val Town is a social website to write and deploy TypeScript functions. Every function gets an API endpoint — instantly. No servers, no Docker, no config files.

What Is Val Town?

Val Town lets you write small TypeScript functions (called vals) that run in the cloud. Every val automatically gets an HTTP endpoint, cron schedule, or email trigger.

How It Works

Create a Val (API endpoint)

// @username/myApi
export default function(req: Request): Response {
  const url = new URL(req.url)
  const name = url.searchParams.get('name') || 'World'
  return Response.json({ message: `Hello, ${name}!`, timestamp: Date.now() })
}
Enter fullscreen mode Exit fullscreen mode

Instantly available at: https://username-myApi.web.val.run?name=Alice

Cron Jobs

// Runs every hour
export default async function() {
  const resp = await fetch('https://api.github.com/repos/denoland/deno/releases/latest')
  const data = await resp.json()
  console.log(`Latest Deno: ${data.tag_name}`)
}
Enter fullscreen mode Exit fullscreen mode

Email Handler

// Receives emails at username.myEmailHandler@valtown.email
export default async function(email: Email) {
  console.log(`From: ${email.from}, Subject: ${email.subject}`)
  // Process and forward
  await fetch('https://hooks.slack.com/services/...', {
    method: 'POST',
    body: JSON.stringify({ text: `New email from ${email.from}: ${email.subject}` })
  })
}
Enter fullscreen mode Exit fullscreen mode

Built-in Storage (SQLite)

import { sqlite } from 'https://esm.town/v/std/sqlite'

// Create table
await sqlite.execute('CREATE TABLE IF NOT EXISTS visits (id INTEGER PRIMARY KEY, url TEXT, ts TEXT)')

// Insert
await sqlite.execute('INSERT INTO visits (url, ts) VALUES (?, ?)', ['/api', new Date().toISOString()])

// Query
const result = await sqlite.execute('SELECT COUNT(*) as total FROM visits')
console.log(`Total visits: ${result.rows[0].total}`)
Enter fullscreen mode Exit fullscreen mode

The Val Town API

# List your vals
curl -s 'https://api.val.town/v1/me/vals' \
  -H 'Authorization: Bearer YOUR_TOKEN' | jq '.data[].name'

# Create a val
curl -s -X POST 'https://api.val.town/v1/vals' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{"name": "myNewVal", "code": "export default () => Response.json({ok: true})", "type": "http"}'

# Run a val
curl -s 'https://api.val.town/v1/run/username.valName' \
  -H 'Authorization: Bearer YOUR_TOKEN'
Enter fullscreen mode Exit fullscreen mode

Real Use Cases

  • Webhook receivers: GitHub, Stripe, Slack webhooks
  • Cron monitors: Check uptime, prices, stock every N minutes
  • Micro APIs: JSON endpoints without a server
  • Email automation: Parse and route incoming emails
  • Data pipelines: Fetch, transform, store data on schedule

Val Town vs Alternatives

Feature Val Town Cloudflare Workers AWS Lambda
Setup time 0 Minutes Hours
Built-in DB SQLite D1 DynamoDB
Social/sharing Yes No No
Free tier Generous 100K req/day 1M req/mo
Email trigger Yes No Via SES

Need to scrape web data for your vals? Scrapfly handles proxies and anti-bot. Email spinov001@gmail.com for custom data pipelines.

Top comments (0)