Write and deploy server-side TypeScript functions instantly with Val Town. Use when someone asks to "deploy a function quickly", "serverless TypeScript", "quick API endpoint", "webhook handler", "cron job in the cloud", "Val Town", "instant API without infrastructure", or "deploy a script without a server". Covers HTTP vals, cron vals, email vals, SQLite storage, and the Val Town API.
Val Town is a platform for writing and deploying TypeScript functions instantly — no infrastructure, no build step, no deployment pipeline. Write a function in the browser, get a URL. HTTP endpoints, cron jobs, email handlers, and persistent SQLite storage. Think "GitHub Gists that run."
// @user/myApi — Deployed instantly at https://user-myapi.web.val.run
export default async function(req: Request): Promise<Response> {
const url = new URL(req.url);
if (req.method === "GET") {
const name = url.searchParams.get("name") || "World";
return Response.json({ message: `Hello, ${name}!` });
}
if (req.method === "POST") {
const body = await req.json();
// Process the data
return Response.json({ received: body, timestamp: Date.now() });
}
return new Response("Method not allowed", { status: 405 });
}
// @user/dailyReport — Runs on a schedule
export default async function() {
// Fetch data from an API
const response = await fetch("https://api.example.com/stats");
const stats = await response.json();
// Send to Slack
await fetch(Deno.env.get("SLACK_WEBHOOK")!, {
method: "POST",
body: JSON.stringify({
text: `📊 Daily Report: ${stats.users} users, ${stats.revenue} revenue`,
}),
});
}
// @user/todoApi — CRUD API with persistent SQLite storage
import { sqlite } from "https://esm.town/v/std/sqlite";
// Initialize table
await sqlite.execute(`
CREATE TABLE IF NOT EXISTS todos (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
done BOOLEAN DEFAULT FALSE,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
)
`);
export default async function(req: Request): Promise<Response> {
const url = new URL(req.url);
if (req.method === "GET") {
const todos = await sqlite.execute("SELECT * FROM todos ORDER BY created_at DESC");
return Response.json(todos.rows);
}
if (req.method === "POST") {
const { title } = await req.json();
await sqlite.execute("INSERT INTO todos (title) VALUES (?)", [title]);
return Response.json({ ok: true }, { status: 201 });
}
if (req.method === "DELETE") {
const id = url.searchParams.get("id");
await sqlite.execute("DELETE FROM todos WHERE id = ?", [id]);
return Response.json({ ok: true });
}
return new Response("Not found", { status: 404 });
}
// @user/stripeWebhook — Handle Stripe webhooks
export default async function(req: Request): Promise<Response> {
const signature = req.headers.get("stripe-signature");
const body = await req.text();
// Verify webhook signature
// In Val Town, use Deno.env.get() for secrets
const secret = Deno.env.get("STRIPE_WEBHOOK_SECRET");
const event = JSON.parse(body);
switch (event.type) {
case "checkout.session.completed":
// Handle successful payment
await fetch("https://api.myapp.com/activate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ customerId: event.data.object.customer }),
});
break;
case "customer.subscription.deleted":
// Handle cancellation
break;
}
return Response.json({ received: true });
}
User prompt: "I need a quick URL that checks if my website is up and returns the status."
The agent will create an HTTP val that fetches the target URL, measures response time, and returns a JSON status report.
User prompt: "When someone stars my GitHub repo, send a message to my Slack channel."
The agent will create an HTTP val that handles GitHub webhook events, filters for star events, and posts to a Slack webhook URL.
Request in, Response outDeno.env.get() — store secrets in Val Town settingsimport { x } from "https://esm.town/v/user/module"npm:package specifiernpx skills add TerminalSkills/val-town下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer