Search

Results include substring matches and semantically similar vals. Learn more
stevekrouse avatar
runGET
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
export let runGET = fetchJSON(
`https://api.val.town/v1/run/stevekrouse.add?args=${JSON.stringify([1, 2])}`,
mattx avatar
examplebotendpoint
@mattx
An interactive, runnable TypeScript val by mattx
Express
export let examplebotendpoint = async (req: Request) => {
const headers = { "Content-type": "application/json" };
const text = await req.text();
const body = JSON.parse(text);
if (
!req.headers.get("X-Signature-Timestamp") ||
!req.headers.get("X-Signature-Ed25519")
return Response.json({ error: "bad request" }, { status: 400 });
const verified = await verify_discord_signature(
process.env.discord_pubkey,
neverstew avatar
thisWebEndpoint
@neverstew
// Forked from @stevekrouse.thisEmail
Script
import { parentReference } from "https://esm.town/v/stevekrouse/parentReference?v=3";
export let thisWebEndpoint = () => {
let { userHandle, valName } = parentReference();
return `https://${userHandle}-${valName}.web.val.run`;
// Forked from @stevekrouse.thisEmail
ejfox avatar
endpointCalculator
@ejfox
* This program creates a basic calculator endpoint that accepts and returns data in the specified format. * It uses a RESTful API approach where the operation is specified in the URL path. * The numbers to operate on are passed as query parameters. * The result is returned as JSON.
HTTP
* This program creates a basic calculator endpoint that accepts and returns data in the specified format.
* It uses a RESTful API approach where the operation is specified in the URL path.
* The numbers to operate on are passed as query parameters.
* The result is returned as JSON.
export default async function server(request: Request): Promise<Response> {
const url = new URL(request.url);
const operation = url.pathname.split('/').pop();
const numbers = url.searchParams.getAll('num').map(Number);
if (!operation || numbers.length === 0) {
return new Response(JSON.stringify({ error: "Invalid request" }), {
eric avatar
metaCall
@eric
An interactive, runnable TypeScript val by eric
Script
export let metaCall = function() {
return this
andreterron avatar
printHeaders
@andreterron
An interactive, runnable TypeScript val by andreterron
Script
export const printHeaders = async (req: express.Request, res) => {
console.log("HEADERS");
console.log(req.options.headers);
res.send(req.options.headers);
stevekrouse avatar
vtTokenSessionAuth
@stevekrouse
Val Town Token Session Auth Protect your vals behind your Val Town API Token. Use session cookies to persist authentication. Forked from @pomdtr/password_auth. Usage import { vtTokenSessionAuth } from "https://esm.town/v/stevekrouse/vtTokenSessionAuthSafe"; export default vtTokenSessionAuth(() => Response.json("Authenticated!")) To sign out, navigate to /signout .
Script
# Val Town Token Session Auth
Protect your vals behind your Val Town API Token. Use session cookies to persist authentication.
Forked from @pomdtr/password_auth.
## Usage
```ts
export default vtTokenSessionAuth(() => Response.json("Authenticated!"))
type Session = {
id: string;
expiresAt: number;
async function createSessionTable(tableName: string) {
lavallee avatar
aqi
@lavallee
An interactive, runnable TypeScript val by lavallee
Cron
export let aqi = async () => {
let pm25 = (
await fetchJSON(
"https://api.openaq.org/v2/latest?" +
new URLSearchParams({
limit: "10",
page: "1",
location: "Miami",
offset: "0",
sort: "desc",
generatecoll avatar
htmlExample
@generatecoll
HTML example This is an example of how to return an HTML response. You can also preview it at https://andreterron-htmlExample.web.val.run?name=Andre
HTTP (deprecated)
# HTML example
This is an example of how to return an HTML response.
You can also preview it at https://andreterron-htmlExample.web.val.run?name=Andre
// View at https://andreterron-htmlExample.web.val.run?name=Andre
export default async function(req: Request): Promise<Response> {
const query = new URL(req.url).searchParams;
// Read name from the querystring or body. Defaults to "you" if not present.
const name = query.get("name") || (await req.json().catch(() => ({}))).name || "you";
// Returns the HTML response
return new Response(`<h1>Hi ${name}!</h1>`, {
adam12 avatar
consoleEmailEx
@adam12
An interactive, runnable TypeScript val by adam12
Script
export let consoleEmailEx = () => {
console.email(`message the current time is ${new Date()}`); // any JSON object can be the message
console.email({ html: "<h1>hello html emails!</h1>" }); // you can send HTML emails
console.email({ hi: "there" }, "Subject Line"); // optional second arg is the subject line
console.email({ html: "<b>hi!</b>", subject: "Subject accepted here too" });
vladimyr avatar
signedFetch
@vladimyr
// SPDX-License-Identifier: 0BSD
Script
// SPDX-License-Identifier: 0BSD
export type SignatureOptions = {
pkcs8: string;
publicKeyId: string | URL;
algorithm?: "rsa-sha256";
signFn?: (message: string, pkcs8: string, algorithm: SignatureOptions["algorithm"]) => Promise<string>;
export function createSignedFetch(
options: SignatureOptions & {
fetch?: typeof fetch;
const fetch = options.fetch ?? globalThis.fetch;
tmcw avatar
activitypub
@tmcw
WebFinger This is a not-quite-complete ActivityPub implementation based on my blog post about building an AP implementation . It includes enough to look up bot@tmcw-activitypub.web.val.run on Mastodon and get some basic information.
HTTP (deprecated)
# WebFinger
This is a not-quite-complete ActivityPub implementation based on my [blog post about building an AP implementation](https://m
export const activitypub = async (req: Request) => {
const { Hono } = await import("npm:hono@3.4.3");
const app = new Hono();
const DOMAIN = "tmcw-activitypub.web.val.run";
const USERS = new Map([
`acct:bot@${DOMAIN}`,
subject: `acct:bot@${DOMAIN}`,
aliases: [],
seanyang0813 avatar
northernChocolateFish
@seanyang0813
An interactive, runnable TypeScript val by seanyang0813
Cron
import { email } from "https://esm.town/v/std/email";
export default async function(interval: Interval) {
await email({
subject: "This is your daily ping!",
text: "Do your daily ping at https://benjaminaster.com/daily-ping/",
xiyouMc avatar
getValTownTest
@xiyouMc
An interactive, runnable TypeScript val by xiyouMc
Script
import { getValTown } from "https://esm.town/v/xiyouMc/getValTown";
export let getValTownTest = (async () => {
return await getValTown();
vladimyr avatar
feps
@vladimyr
An interactive, runnable TypeScript val by vladimyr
HTTP (deprecated)
import { Hono } from "npm:hono@3.12.7";
const app = new Hono();
app.get("/:fepId{[A-za-z0-9]{4}}", (c) => {
const fepId = c.req.param("fepId").toLowerCase();
return c.redirect(`https://codeberg.org/fediverse/fep/src/branch/main/fep/${fepId}/fep-${fepId}.md`);
export default app.fetch;